添加商品签约图片
This commit is contained in:
parent
932bffb5c7
commit
af7c76697d
@ -24,6 +24,8 @@ use app\models\Model;
|
||||
* @property int $deleted_at 删除时间
|
||||
* @property int $is_delete 是否删除,0=否,1=是
|
||||
* @property int $type 商品类型:0=实体商品
|
||||
* @property int $signing_head_img 签约头部图片
|
||||
* @property int $signing_foot_img 签约底部图片
|
||||
*/
|
||||
class GoodsHub extends \yii\db\ActiveRecord
|
||||
{
|
||||
|
||||
@ -12,4 +12,9 @@ class Signing extends ActiveRecord
|
||||
return '{{%signing}}';
|
||||
}
|
||||
|
||||
|
||||
public function getGoods()
|
||||
{
|
||||
return $this->hasOne(Goods::className(), ['id' => 'goods_id']);
|
||||
}
|
||||
}
|
||||
@ -56,7 +56,6 @@ class CommonGoodsEditForm extends Model
|
||||
|
||||
public $newAttrs;
|
||||
|
||||
|
||||
public $banner_urls;
|
||||
public $video_banner_urls;
|
||||
|
||||
@ -66,12 +65,14 @@ class CommonGoodsEditForm extends Model
|
||||
public $cat3_id;
|
||||
public $cat4_id;
|
||||
public $date;
|
||||
public $signing_foot_img;
|
||||
public $signing_head_img;
|
||||
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[['name', 'subtitle', 'detail', 'cover_pic', 'video_url', 'unit', 'plugin_sign', 'goods_no',], 'trim'],
|
||||
[['name', 'subtitle', 'detail', 'cover_pic', 'video_url', 'video_banner_urls', 'banner_urls', 'unit', 'plugin_sign', 'goods_no', 'date'], 'string'],
|
||||
[['name', 'subtitle', 'detail', 'cover_pic', 'video_url', 'video_banner_urls', 'banner_urls', 'unit', 'plugin_sign', 'goods_no', 'date','signing_head_img','signing_foot_img'], 'string'],
|
||||
[['original_price', 'cost_price', 'price', 'goods_weight'], 'number'],
|
||||
[['type', 'use_attr', 'goods_stock', 'virtual_sales', 'confine_count', 'freight_id', 'sort', 'cx_mch_id'], 'integer'],
|
||||
|
||||
@ -134,7 +135,7 @@ class CommonGoodsEditForm extends Model
|
||||
// $this->model->attr_groups = json_encode($this->attrGroups,JSON_UNESCAPED_UNICODE);
|
||||
$this->model->attr_groups = 1; //商品规格组 用不到看表 0 不需要规格组
|
||||
|
||||
$this->model->date = (int)strtotime($this->date."-01-01");
|
||||
$this->model->date = (int)strtotime($this->date . "-01-01");
|
||||
|
||||
|
||||
//保存商品基础信息
|
||||
@ -179,7 +180,8 @@ class CommonGoodsEditForm extends Model
|
||||
$goods_hub->cost_price = $this->cost_price ? $this->cost_price : $this->price;
|
||||
$goods_hub->detail = $this->detail;
|
||||
$goods_hub->cover_pic = $this->cover_pic;
|
||||
|
||||
$goods_hub->signing_head_img = $this->signing_head_img;
|
||||
$goods_hub->signing_foot_img = $this->signing_foot_img;
|
||||
$goods_hub->banner_urls = $this->banner_urls;
|
||||
|
||||
|
||||
|
||||
@ -227,7 +227,29 @@ $this->params['breadcrumbs'][] = $this->title;
|
||||
// 'imageCompressEnable' => 1,
|
||||
// 'imageCompressBorder' => 750,
|
||||
]) ?>
|
||||
<?= PickFile::widget([
|
||||
'accept' => 'images',
|
||||
'id' => 'signing_head_img',
|
||||
'name' => 'signing_head_img',
|
||||
'label' => '签约头部图片',
|
||||
'value' => $model->goodsHub ? $model->goodsHub->signing_head_img : '',
|
||||
// 'tip' => '图片大小750×750',
|
||||
'required' => true,
|
||||
'imageCompressEnable' => 1,
|
||||
'imageCompressBorder' => 750,
|
||||
]) ?>
|
||||
|
||||
<?= PickFile::widget([
|
||||
'accept' => 'images',
|
||||
'id' => 'signing_foot_img',
|
||||
'name' => 'signing_foot_img',
|
||||
'label' => '签约底部图片',
|
||||
'value' => $model->goodsHub ? $model->goodsHub->signing_foot_img : '',
|
||||
// 'tip' => '图片大小750×750',
|
||||
'required' => true,
|
||||
'imageCompressEnable' => 1,
|
||||
'imageCompressBorder' => 750,
|
||||
]) ?>
|
||||
|
||||
|
||||
<div class="layui-form-item">
|
||||
|
||||
@ -4,10 +4,23 @@ namespace app\modules\api\controllers;
|
||||
|
||||
use app\components\SiteHelper;
|
||||
use app\modules\api\models\SigningForm;
|
||||
use app\modules\api\behaviors\LoginBehavior;
|
||||
|
||||
class SigningController extends Controller
|
||||
{
|
||||
|
||||
public function behaviors()
|
||||
{
|
||||
return array_merge(parent::behaviors(), [
|
||||
'login' => [
|
||||
'class' => LoginBehavior::className(),
|
||||
'ignore' => [
|
||||
'api/signing/signing-list'
|
||||
]
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* showdoc
|
||||
* @catalog 签约订单
|
||||
@ -16,7 +29,6 @@ class SigningController extends Controller
|
||||
* @method get
|
||||
* @url /api/signing/signing-type
|
||||
* @return {"code":0,"msg":"ok","data":[]}
|
||||
|
||||
* @remark
|
||||
*/
|
||||
public function actionSigningType()
|
||||
@ -34,7 +46,6 @@ class SigningController extends Controller
|
||||
* @method get
|
||||
* @url /api/signing/signing
|
||||
* @return {"code":0,"msg":"ok","data":[]}
|
||||
|
||||
* @remark
|
||||
*/
|
||||
public function actionSigning()
|
||||
@ -59,7 +70,6 @@ class SigningController extends Controller
|
||||
* @param number 必选 int 签约年限
|
||||
* @param remark 必选 int 备注
|
||||
* @return {"code":0,"msg":"ok","data":[]}
|
||||
|
||||
* @remark
|
||||
*/
|
||||
public function actionSigningAdd()
|
||||
@ -68,12 +78,12 @@ class SigningController extends Controller
|
||||
$data = $this->invaildRequest();
|
||||
return $this->responseHandler($data);
|
||||
}
|
||||
|
||||
$signingForm = new SigningForm();
|
||||
|
||||
$signingForm->attributes = \Yii::$app->request->post();
|
||||
$signingForm->user_id = \Yii::$app->user->identity->id;
|
||||
|
||||
return $signingForm->add();
|
||||
return $this->responseHandler($signingForm->add());
|
||||
|
||||
}
|
||||
|
||||
@ -86,7 +96,6 @@ class SigningController extends Controller
|
||||
* @url /api/signing/signing-detail
|
||||
* @param order_no 必选 int 订单号
|
||||
* @return {"code":0,"msg":"ok","data":[]}
|
||||
|
||||
* @remark
|
||||
*/
|
||||
|
||||
@ -95,8 +104,8 @@ class SigningController extends Controller
|
||||
$orderNo = \Yii::$app->request->get('order_no');
|
||||
|
||||
$signingForm = new SigningForm();
|
||||
|
||||
return $signingForm->orderDetail($orderNo);
|
||||
$signingForm->user_id = \Yii::$app->user->identity->id;
|
||||
return $this->responseHandler($signingForm->orderDetail($orderNo));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -108,16 +117,18 @@ class SigningController extends Controller
|
||||
* @url /api/signing/signing-list
|
||||
* @param status 可选 int 订单状态
|
||||
* @return {"code":0,"msg":"ok","data":[]}
|
||||
|
||||
* @remark
|
||||
*/
|
||||
public function actionSigningList()
|
||||
{
|
||||
$signingForm = new SigningForm();
|
||||
$signingForm->user_id = \Yii::$app->user->identity->id;
|
||||
|
||||
$status = \Yii::$app->request->get('status');
|
||||
$limit = \Yii::$app->request->get('limit',10);
|
||||
$page = \Yii::$app->request->get('page',1);
|
||||
|
||||
return $signingForm->orderList($status);
|
||||
return $this->responseHandler($signingForm->orderList($status,$limit,$page));
|
||||
}
|
||||
|
||||
}
|
||||
@ -2,7 +2,9 @@
|
||||
|
||||
namespace app\modules\api\models;
|
||||
|
||||
use app\models\Goods;
|
||||
use app\models\GoodsHub;
|
||||
use app\models\Model;
|
||||
use app\models\Signing;
|
||||
use yii\data\Pagination;
|
||||
|
||||
@ -19,23 +21,26 @@ class SigningForm extends ApiModel
|
||||
public $number;
|
||||
|
||||
public $remark;
|
||||
public $user_id;
|
||||
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[['goods_hub_id', 'company_name', 'brand_name', 'product', 'type', 'number', 'remark'], 'required'],
|
||||
[['goods_hub_id', 'number'], 'integer']
|
||||
[['goods_hub_id', 'company_name', 'brand_name', 'product', 'type', 'number'], 'required'],
|
||||
[['goods_hub_id', 'number'], 'integer'],
|
||||
[['remark'], 'string']
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
public function add()
|
||||
{
|
||||
|
||||
if (!$this->validate()) {
|
||||
return $this->getModelError();
|
||||
}
|
||||
|
||||
$goods = GoodsHub::findOne($this->goods_hub_id);
|
||||
$goods = Goods::findOne($this->goods_hub_id);
|
||||
|
||||
if (!$goods) {
|
||||
return $this->apiReturnError('商品id异常');
|
||||
@ -44,9 +49,9 @@ class SigningForm extends ApiModel
|
||||
$signing = new Signing();
|
||||
|
||||
$signing->order_no = $this->orderNo();
|
||||
$signing->user_id = \Yii::$app->user->identity->id;
|
||||
$signing->goods_hub_id = $this->goods_hub_id;
|
||||
$signing->moy = $goods->original_price * $this->number;
|
||||
$signing->user_id = $this->user_id;
|
||||
$signing->goods_id = $goods->id;
|
||||
$signing->moy = $goods->price * $this->number;
|
||||
$signing->company_name = $this->company_name;
|
||||
$signing->brand_name = $this->brand_name;
|
||||
$signing->product = $this->product;
|
||||
@ -55,16 +60,15 @@ class SigningForm extends ApiModel
|
||||
$signing->remark = $this->remark;
|
||||
$signing->create_time = time();
|
||||
|
||||
return $signing->save();
|
||||
|
||||
return $signing->save() ? $this->apiReturnSuccess('success', ['order_no' => $signing->order_no]) : $this->apiReturnError('error');
|
||||
}
|
||||
|
||||
|
||||
private function orderNo()
|
||||
{
|
||||
$orderNo = mt_rand(100000000000, 99999999999);
|
||||
$orderNo = mt_rand(100000000000, 9999999999999);
|
||||
|
||||
if (Signing::find()->where('order_no', $orderNo)->count()) {
|
||||
if (Signing::find()->where(['order_no' => $orderNo])->count('id')) {
|
||||
return $this->orderNo();
|
||||
}
|
||||
return $orderNo;
|
||||
@ -73,31 +77,34 @@ class SigningForm extends ApiModel
|
||||
|
||||
public function orderDetail($orderNo)
|
||||
{
|
||||
$order = Signing::find()->where('order_no', $orderNo)
|
||||
->where('user_id', \Yii::$app->user->identity->id)->one()->toArray();
|
||||
|
||||
$order = Signing::find()->andWhere(['order_no' => $orderNo, 'user_id' => $this->user_id])->one()->toArray();
|
||||
|
||||
if (!$order) {
|
||||
return $this->apiReturnError('订单号错误');
|
||||
}
|
||||
|
||||
$order['goods'] = GoodsHub::findOne($order['goods_hub_id']);
|
||||
$order['goods'] = Goods::findOne($order['goods_id']);
|
||||
|
||||
$order['goods_hub'] = GoodsHub::findOne($order['goods']['goods_hub_id']);
|
||||
|
||||
return $this->apiReturnSuccess('success', $order);
|
||||
}
|
||||
|
||||
public function orderList($status)
|
||||
public function orderList($status, $limit, $page)
|
||||
{
|
||||
|
||||
$query = Signing::find()->where('user_id', \Yii::$app->user->identity->id);
|
||||
$query = Signing::find()->with(['goods.goodsHub'])->where(['user_id' =>$this->user_id]);
|
||||
|
||||
if ($status) {
|
||||
$query->where('status', $status);
|
||||
$query->where(['status' => $status]);
|
||||
}
|
||||
|
||||
$pagination = new Pagination(['totalCount' => $query->count(), 'defaultPageSize' => 2]);
|
||||
$pagination = new Pagination(['totalCount' => $query->count(), 'defaultPageSize' => $limit]);
|
||||
|
||||
$models = $query->offset($pagination->offset)->limit($pagination->limit)->all();
|
||||
$models = $query->offset($pagination->offset)->limit($pagination->limit)->asArray()->all();
|
||||
|
||||
return $this->apiReturnSuccess('success', $models);
|
||||
|
||||
return $this->apiReturnSuccess('success', ['pagination' => $pagination, 'data' => $models]);
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user