|
@@ -9,9 +9,12 @@ namespace app\admin\controller\order;
|
|
|
|
|
|
use app\admin\controller\AuthController;
|
|
|
use app\admin\model\order\StoreOrderCartInfo;
|
|
|
+use app\admin\model\store\StoreProductAttrValue;
|
|
|
use app\admin\model\system\Express;
|
|
|
use app\admin\model\system\SystemStoreBill;
|
|
|
use app\admin\model\system\SystemStoreSender;
|
|
|
+use app\models\store\StoreCart;
|
|
|
+use app\models\store\StoreExchange;
|
|
|
use app\models\store\StoreExchangeOrder;
|
|
|
use crmeb\repositories\OrderRepository;
|
|
|
use crmeb\repositories\ShortLetterRepositories;
|
|
@@ -1151,4 +1154,74 @@ class StoreOrder extends AuthController
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ public function add_gift_ticket()
|
|
|
+ {
|
|
|
+ $f = [];
|
|
|
+ $attrs = [];
|
|
|
+ $products = StoreExchange::seckillList();
|
|
|
+ foreach ($products as $v) {
|
|
|
+ $list = StoreProductAttrValue::where('type', 5)->where('product_id', $v['id']);
|
|
|
+ foreach ($list as $vv) {
|
|
|
+ $attrs[] = ['value' => $v['id'] . '|' . $v['product_id'] . '|' . $vv['unique'], 'label' => $v['title'] . '[' . $vv['suk'] . ']' . ':¥' . $vv['price']];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $f[] = Form::select('product', '赠送商品')->setOptions($attrs)->filterable(true);
|
|
|
+ $f[] = Form::number('num', '赠送个数')->required()->step(1)->min(1);
|
|
|
+ $f[] = Form::select('uid', '赠送会员')->setOptions(function () {
|
|
|
+ return User::where('status', 1)->field('uid as value,nickname as label')->select()->toArray();
|
|
|
+ })->filterable(true);
|
|
|
+ $form = Form::make_post_form('添加用户通知', $f, Url::buildUrl('save_gift_ticket'));
|
|
|
+ $this->assign(compact('form'));
|
|
|
+ return $this->fetch('public/form-builder');
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public function save_gift_ticket()
|
|
|
+ {
|
|
|
+ list($product, $num, $uid) = Util::postMore([
|
|
|
+ ['product', ''],
|
|
|
+ ['num', 0],
|
|
|
+ ['uid', 0],
|
|
|
+ ], $this->request, true);
|
|
|
+ if (!$uid || !$num) {
|
|
|
+ Json::fail('请选择赠送的用户及赠送的数量');
|
|
|
+ }
|
|
|
+ $product = explode('|', $product);
|
|
|
+ $exchange_id = $product[0] ?? 0;
|
|
|
+ $product_id = $product[1] ?? 0;
|
|
|
+ $uni = $product[2] ?? '';
|
|
|
+ if (!$product_id || !$exchange_id || !$uni) {
|
|
|
+ Json::fail('请选择赠送的商品');
|
|
|
+ }
|
|
|
+ $res = StoreCart::setCart($uid, $product_id, $num, $uni, 'product', 1, 0, 0, 0, 0, $exchange_id);
|
|
|
+ if ($res) {
|
|
|
+ $cartId = $res->id;
|
|
|
+ $cartGroup = StoreCart::getUserProductCartList($uid, [$cartId], 1);
|
|
|
+ if (count($cartGroup['invalid'])) Json::fail($cartGroup['invalid'][0]['productInfo']['store_name'] . '已失效!');
|
|
|
+ if (!$cartGroup['valid']) Json::fail('请提交购买的商品');
|
|
|
+ $cartInfo = $cartGroup['valid'];
|
|
|
+ $priceGroup = \app\models\store\StoreOrder::getOrderPriceGroup($cartInfo, 0);
|
|
|
+ $other = [
|
|
|
+ 'offlinePostage' => sys_config('offline_postage'),
|
|
|
+ 'integralRatio' => sys_config('integral_ratio'),
|
|
|
+ 'store_id' => 0,
|
|
|
+ ];
|
|
|
+ $orderKey = \app\models\store\StoreOrder::cacheOrderInfo($uid, $cartInfo, $priceGroup, $other);
|
|
|
+ if (!$orderKey) Json::fail('生成订单错误!');
|
|
|
+ if (\app\models\store\StoreOrder::be(['order_id|unique' => $orderKey, 'uid' => $uid, 'is_del' => 0]))
|
|
|
+ Json::fail('订单已生成');
|
|
|
+ $order = \app\models\store\StoreOrder::cacheKeyCreateOrder($uid, $orderKey, 0, 'weixin', false, 0, '系统后台订单', 0, 0, 0, 0, 0, $exchange_id, false, 1, 2, '', '', 0, 0, 1, 1);
|
|
|
+ if ($order === false) Json::fail(\app\models\store\StoreOrder::getErrorInfo('订单生成失败'));
|
|
|
+ else $res = \app\models\store\StoreOrder::jsPayPrice($order['order_id'], $uid);
|
|
|
+ if ($res) {
|
|
|
+ Json::successful('支付成功');
|
|
|
+ }
|
|
|
+ Json::fail('支付失败');
|
|
|
+ } else {
|
|
|
+ Json::fail('加入购物车失败');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|