| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867 |
- <?php
- namespace app\modules\client\models\v1;
- use app\constants\OptionSetting;
- use app\models\District;
- use app\models\Favorite;
- use app\models\Goods;
- use app\models\GoodsPic;
- use app\models\Option;
- use app\models\Order;
- use app\models\OrderComment;
- use app\models\OrderDetail;
- use app\models\Worker;
- use app\models\WorkerCat;
- use app\models\WorkerGoods;
- use app\models\WorkerGoodsCat;
- use app\models\WorkerGoodsExt;
- use app\models\WorkerLevel;
- use app\models\WorkerOrderExt;
- use app\models\WorkerPic;
- use app\models\WorkerSetting;
- use yii\base\Model;
- use yii\helpers\Json;
- use app\utils\Notice\NoticeSend;
- class WorkerOrderForm extends Model
- {
- public $latitude;
- public $longitude;
- public $store_id;
- public $status;
- public $_from;
- public $goods_id;
- public $goods_ids;
- public $id;
- public function rules()
- {
- return [
- [['latitude', 'longitude', '_from', 'goods_ids'], 'string'],
- [['store_id', 'id', 'status', 'goods_id'], 'integer']
- ];
- }
- public function workerOrderList() {
- try {
- $store_id = $this->store_id;
- $user_id = get_user_id();
- $status = $this->status;
- $query = Order::find()->alias('o')->where(['o.store_id' => $store_id, 'o.order_type' => 6, 'o.user_id' => $user_id])
- ->leftJoin(['woe' => WorkerOrderExt::tableName()], 'o.id = woe.order_id')
- ->leftJoin(['oc' => OrderComment::tableName()], 'o.id = oc.order_id');
- if (!is_null($status) && $status > -1) {
- switch ($status) {
- case 0: //未开始
- $query->andWhere(['woe.status_ext' =>
- [
- WorkerOrderExt::STATUS_EXT_WAIT_BIND,
- WorkerOrderExt::STATUS_EXT_WAIT_BIND_OK
- ]
- ]);
- break;
- case 1: //进行中
- $query->andWhere(['woe.status_ext' => [
- WorkerOrderExt::STATUS_EXT_START,
- WorkerOrderExt::STATUS_EXT_HAS_BIND,
- WorkerOrderExt::STATUS_EXT_ON_ROAD,
- WorkerOrderExt::STATUS_EXT_ARRIVE
- ]]);
- break;
- case 2: //待评价
- $query->andWhere(['AND', ['woe.status_ext' => WorkerOrderExt::STATUS_EXT_FINISH], ['IS', 'oc.id', null]]);
- break;
- case 4: //待支付
- $query->andWhere(['woe.status_ext' => WorkerOrderExt::STATUS_EXT_WAIT_PAY]);
- break;
- default: //已取消
- $query->andWhere(['OR', ['woe.status_ext' => WorkerOrderExt::STATUS_EXT_CANCEL], ['AND', ['woe.status_ext' => WorkerOrderExt::STATUS_EXT_WAIT_BIND], ['<', 'o.created_at', (time() - 900)]]]);
- break;
- }
- }
- $query->select('o.id, woe.worker_id, woe.status_ext, o.book_info, o.order_type_ext, o.pay_price, o.created_at, o.is_pay, o.apply_delete');
- $query->orderBy('o.created_at desc');//woe.status_ext ASC,
- $list = pagination_make($query);
- foreach ($list['list'] as &$item) {
- $order = Order::findOne($item['id']);
- if (time() - $order->created_at > 15 * 60 && intval($order->trade_status) != Order::ORDER_FLOW_CANCEL && intval($order->is_pay) === 0) {
- $order->trade_status = Order::ORDER_FLOW_CANCEL;
- $order->updated_at = time();
- $order->save();
- }
- $item['goods_list'] = OrderDetail::find()->alias('od')->where(['od.order_id' => $item['id']])
- ->leftJoin(['g' => Goods::tableName()], 'od.goods_id = g.id')
- ->leftJoin(['wge' => WorkerGoodsExt::tableName()], 'wge.goods_id = g.id')
- ->select('od.goods_id, od.goods_name, od.num, od.pic goods_pic, od.total_price, od.pre_price, wge.payment_type')->asArray()->all();
- $num = array_sum(array_column($item['goods_list'], 'num'));
- $price = $item['pay_price'] / $num;
- foreach ($item['goods_list'] as &$goods) {
- $goods['is_comment'] = intval(OrderComment::findOne(['order_id' => $item['id'], 'goods_id' => $goods['goods_id']]));
- $goods['payment_type'] = intval($goods['payment_type']);
- $goods['book_info'] = json_decode($item['book_info'], true);
- $goods['price'] = sprintf('%.2f', $price * $goods['num']);
- //$goods['price'] = $goods['payment_type'] && intval($item['order_type_ext']) === 601 ? $goods['pre_price'] : $goods['total_price'];
- }
- $worker = Worker::findOne($item['worker_id']);
- $item['worker'] = $worker ? [
- 'id' => $worker->id,
- 'name' => $worker->name,
- 'level_name' => WorkerLevel::findOne(['store_id' => $store_id, 'level' => $worker->level])->name ?? '服务人员',
- 'logo' => $worker->logo
- ] : null;
- $item['book_info'] = json_decode($item['book_info'], true);
- $item['status'] = -1;
- $item['is_pay'] = (int)$item['is_pay'];
- $item['status_ext'] = (int)$item['status_ext'];
- if (in_array($item['status_ext'], [10, 15, 20, 30, 40])) {
- $item['status'] = 0;
- }
- if ($item['status_ext'] === 50) {
- $item['status'] = 1;
- }
- if ($item['status_ext'] === 100) {
- $item['status'] = 3;
- $comment_ = OrderComment::find()->where(['order_id' => $item['id']])->select('id')->column();
- if (count($comment_) !== count($item['goods_list'])) {
- $item['status'] = 2;
- }
- }
- if ($item['status_ext'] === 70 || $item['status_ext'] === 5 && ($item['created_at'] + 900) < time()) {
- $item['status'] = 4;
- }
- $item['pay_type_list'] = $this->getPayType();
- $item['apply_delete'] = intval($item['apply_delete']);
- }
- return [
- 'code' => 0,
- 'msg' => 'success',
- 'data' => [
- 'list' => $list['list'],
- 'pageNo' => $list['pageNo'],
- 'totalCount' => $list['totalCount']
- ],
- ];
- } catch (\Exception $e) {
- return [
- 'code' => 1,
- 'msg' => $e->getMessage()
- ];
- }
- }
- public function workerOrderCancelReason() {
- return [
- 'code' => 0,
- 'msg' => 'success',
- 'data' => [
- [
- 'status' => 0,
- 'msg' => '不想要了'
- ],
- [
- 'status' => 1,
- 'msg' => '商品错选/多选'
- ],
- [
- 'status' => 2,
- 'msg' => '商品无货'
- ],
- [
- 'status' => 3,
- 'msg' => '地址信息填写错误'
- ],
- [
- 'status' => 4,
- 'msg' => '商品降价'
- ],
- [
- 'status' => 5,
- 'msg' => '价格高于其他平台'
- ],
- [
- 'status' => 6,
- 'msg' => '没用/少用/错用优惠'
- ],
- ]
- ];
- }
- public function workerOrderInfo() {
- try {
- $id = $this->id;
- $store_id = $this->store_id;
- $user_id = get_user_id();
- if (!$id) {
- throw new \Exception('参数错误');
- }
- $info = Order::find()->alias('o')->where(['o.id' => $id, 'o.user_id' => $user_id])
- ->leftJoin(['woe' => WorkerOrderExt::tableName()], 'o.id = woe.order_id')
- ->select('o.id, o.order_no, o.pay_type, o.book_info, o.express_price, o.total_price, o.pay_price,
- o.created_at, woe.status_ext, woe.worker_id, o.name, o.mobile, o.address, woe.time_start_service, woe.user_revoke_reason')->asArray()->one();
- $info['status'] = -1;
- $info['status_ext'] = (int)$info['status_ext'];
- if (in_array($info['status_ext'], [10, 15, 20, 30, 40])) {
- $info['status'] = 0;
- }
- if ($info['status_ext'] === 50) {
- $info['status'] = 1;
- }
- if ($info['status_ext'] === 70 || $info['status'] === -1 && ($info['created_at'] + 900) < time()) {
- $info['status'] = 4;
- }
- $info['pay_type'] = intval($info['pay_type']);
- $info['created_at_str'] = date("Y-m-d H:i:s", $info['created_at']);
- $info['time_start_service'] = $info['time_start_service'] ? date("Y-m-d H:i:s", $info['time_start_service']) : '';
- $info['time_end_service'] = $info['time_end_service'] ? date("Y-m-d H:i:s", $info['time_end_service']) : '';
- $info['goods_list'] = OrderDetail::find()->alias('od')->where(['od.order_id' => $info['id']])
- ->leftJoin(['g' => Goods::tableName()], 'od.goods_id = g.id')
- ->leftJoin(['wge' => WorkerGoodsExt::tableName()], 'wge.goods_id = g.id')
- ->select('g.id goods_id, od.pic goods_pic, od.goods_name, od.total_price, od.num, od.pre_price, wge.payment_type')->asArray()->all();
- if ($info['status_ext'] === 100) {
- $info['status'] = 3;//OrderComment::findOne(['order_id' => $info['id']]) ? 3 : 2;
- $comment_ = OrderComment::find()->where(['order_id' => $info['id']])->select('id')->column();
- if (count($comment_) !== count($info['goods_list'])) {
- $info['status'] = 2;
- }
- }
- $info['goods_price'] = 0;
- $info['progress'] = $this->workerOrderProgress()['data']['progress'];
- if ($info['goods_list']) {
- foreach ($info['goods_list'] as &$item) {
- if (intval($item['payment_type']) === 1) {
- $item['price'] = $item['pre_price'];
- } else {
- $item['price'] = $item['total_price'];
- }
- $info['goods_price'] += $item['price'];
- $item['is_comment'] = intval($info['status'] === 2 && !OrderComment::findOne(['order_id' => $info['id'], 'goods_id' => $item['goods_id']])) ? 0 : 1;
- $item['book_info'] = json_decode($info['book_info'], true);
- }
- }
- $info['pay_type_list'] = $this->getPayType();
- $info['goods_price'] = sprintf('%.2f', $info['goods_price']);
- $worker = Worker::findOne($info['worker_id']);
- $info['worker'] = $worker ? [
- 'id' => $worker->id,
- 'name' => $worker->name,
- 'level_name' => WorkerLevel::findOne(['store_id' => $store_id, 'level' => $worker->level])->name ?? '服务人员',
- 'logo' => $worker->logo
- ] : null;
- return [
- 'code' => 0,
- 'msg' => '获取成功',
- 'data' => $info
- ];
- } catch (\Exception $e) {
- return [
- 'code' => 1,
- 'msg' => $e->getMessage()
- ];
- }
- }
- //服务人员进度
- public function workerOrderProgress() {
- try {
- $id = $this->id;
- $store_id = $this->store_id;
- $order_ext = Order::find()->alias('o')->leftJoin(['woe' => WorkerOrderExt::tableName()], 'o.id = woe.order_id')
- ->where(['order_id' => $id])->select('woe.status_ext, woe.time_outgoing, woe.time_has_bind,
- woe.time_reach, woe.time_start_service, woe.time_end_service, woe.time_user_revoke, o.created_at, woe.worker_id, woe.user_revoke, o.name, o.mobile, o.address')->asArray()->one();
- $progress = [];
- $t_date = date("Ymd");
- $order_ext['status_ext'] = (int)$order_ext['status_ext'];
- if ($order_ext['status_ext'] > 5) {
- $date = date('Ymd', $order_ext['created_at']);
- $text = date('m.d', $order_ext['created_at']);
- if (($t_date-$date) == 0) {
- $text = "今天 ";
- }
- if (($t_date-$date) == 1) {
- $text = "昨天 ";
- }
- $progress = [
- [
- 'status' => 0,
- 'time' => $text . date('H:i', $order_ext['created_at']),
- 'msg' => '商品已经下单'
- ]
- ];
- }
- //已接单
- if ($order_ext['status_ext'] >= 20) {
- if (($order_ext['status_ext'] === 70 && ($order_ext['time_has_bind'] < $order_ext['time_user_revoke'])) || ($order_ext['status_ext'] !== 70)) {
- $date = date('Ymd', $order_ext['time_has_bind']);
- $text = date('m.d', $order_ext['time_has_bind']);
- if (($t_date-$date) == 0) {
- $text = "今天 ";
- }
- if (($t_date-$date) == 1) {
- $text = "昨天 ";
- }
- $worker = Worker::findOne($order_ext['worker_id']);
- $name = $worker->name ?? '-';
- $tel = $worker->tel ?? '-';
- $progress = array_merge([
- [
- 'status' => 1,
- 'time' => $order_ext['time_has_bind'] > 0 ? $text . date('H:i', $order_ext['time_has_bind']) : '',
- 'msg' => '您的订单已由【' . $name . '】接单。等待出发 联系人姓名:' . $name. ',电话' . $tel
- ]
- ], $progress);
- }
- }
- //已出发
- if ($order_ext['status_ext'] >= 30) {
- if (($order_ext['status_ext'] === 70 && ($order_ext['time_outgoing'] < $order_ext['time_user_revoke'])) || ($order_ext['status_ext'] !== 70)) {
- $date = date('Ymd', $order_ext['time_outgoing']);
- $text = date('m.d', $order_ext['time_outgoing']);
- if (($t_date-$date) == 0) {
- $text = "今天 ";
- }
- if (($t_date-$date) == 1) {
- $text = "昨天 ";
- }
- $progress = array_merge([
- [
- 'status' => 2,
- 'time' => $order_ext['time_outgoing'] > 0 ? $text . date('H:i', $order_ext['time_outgoing']) : '',
- 'msg' => '服务人员已出发'
- ]
- ], $progress);
- }
- }
- // 已到达
- if ($order_ext['status_ext'] >= 40) {
- if (($order_ext['status_ext'] === 70 && ($order_ext['time_reach'] < $order_ext['time_user_revoke'])) || ($order_ext['status_ext'] !== 70)) {
- $date = date('Ymd', $order_ext['time_reach']);
- $text = date('m.d', $order_ext['time_reach']);
- if (($t_date-$date) == 0) {
- $text = "今天 ";
- }
- if (($t_date-$date) == 1) {
- $text = "昨天 ";
- }
- $progress = array_merge([
- [
- 'status' => 3,
- 'time' => $order_ext['time_reach'] > 0 ? $text . date('H:i', $order_ext['time_reach']) : '',
- 'msg' => '服务人员已到达'
- ]
- ], $progress);
- }
- }
- // 服务中
- if ($order_ext['status_ext'] >= 50) { //
- //已取消
- if (($order_ext['status_ext'] === 70 && ($order_ext['time_start_service'] < $order_ext['time_user_revoke'])) || ($order_ext['status_ext'] !== 70)) {
- $date = date('Ymd', $order_ext['time_start_service']);
- $text = date('m.d', $order_ext['time_start_service']);
- if (($t_date-$date) == 0) {
- $text = "今天 ";
- }
- if (($t_date-$date) == 1) {
- $text = "昨天 ";
- }
- $progress = array_merge([
- [
- 'status' => 4,
- 'time' => $order_ext['time_start_service'] > 0 ? $text . date('H:i', $order_ext['time_start_service']) : '',
- 'msg' => '服务人员已开始服务'
- ]
- ], $progress);
- }
- }
- // 已完成
- if ($order_ext['status_ext'] == 100) {
- $date = date('Ymd', $order_ext['time_end_service']);
- $text = date('m.d', $order_ext['time_end_service']);
- if (($t_date-$date) == 0) {
- $text = "今天 ";
- }
- if (($t_date-$date) == 1) {
- $text = "昨天 ";
- }
- $progress = array_merge([
- [
- 'status' => 5,
- 'time' => $order_ext['time_end_service'] > 0 ? $text . date('H:i', $order_ext['time_end_service']) : '',
- 'msg' => '服务人员已完成服务'
- ]
- ], $progress);
- }
- // 已取消
- if ($order_ext['status_ext'] == 70 || $order_ext['user_revoke']) {
- $date = date('Ymd', $order_ext['time_user_revoke']);
- $text = date('m.d', $order_ext['time_user_revoke']);
- if (($t_date-$date) == 0) {
- $text = "今天 ";
- }
- if (($t_date-$date) == 1) {
- $text = "昨天 ";
- }
- $progress = array_merge([
- [
- 'status' => 6,
- 'time' => $order_ext['time_end_service'] > 0 ? $text . date('H:i', $order_ext['time_end_service']) : '',
- 'msg' => '订单已取消'
- ]
- ], $progress);
- }
- $worker = Worker::findOne($order_ext['worker_id']);
- return [
- 'code' => 0,
- 'msg' => 'success',
- 'data' => [
- 'progress' => $progress,
- 'worker' => [
- 'id' => $worker->id ?? '',
- 'name' => $worker->name ?? '',
- 'level_name' => WorkerLevel::findOne(['store_id' => $store_id, 'level' => $worker->level])->name ?? '服务人员',
- 'logo' => $worker->logo ?? '',
- 'tel' => $worker->tel ?? ''
- ],
- 'address' => [
- 'name' => $order_ext['name'],
- 'mobile' => $order_ext['mobile'],
- 'address' => $order_ext['address'],
- ]
- ]
- ];
- } catch (\Exception $e) {
- return [
- 'code' => 1,
- 'msg' => $e->getMessage()
- ];
- }
- }
- //未支付订单取消 / 20250326增加已支付订单退款功能 已支付未接单状态
- public function workerOrderCancel() {
- try {
- $id = $this->id;
- $status = $this->status;
- $order = Order::find()->alias('o')->leftJoin(['woe' => WorkerOrderExt::tableName()], 'woe.order_id = o.id')
- ->where(['o.id' => $id])->select('o.id, o.created_at, woe.status_ext, o.trade_status, o.apply_delete')->asArray()->one();
- $order['status_ext'] = (int)$order['status_ext'];
- if (intval($order['trade_status']) === Order::ORDER_FLOW_CANCEL) {
- throw new \Exception('订单已经取消');
- }
- if (intval($order['apply_delete']) === Order::ORDER_APPLY_DELETE) {
- throw new \Exception('订单取消申请中');
- }
- if (($order['status_ext'] > 10 && $order['status_ext'] !== 70)) {
- throw new \Exception('当前订单状态不可取消');
- }
- $result = $this->workerOrderCancelReason();
- $data = $result['data'];
- $status_arr = array_column($data, 'status');
- if (!in_array($status, $status_arr)) {
- throw new \Exception('状态错误');
- }
- $order_ext = WorkerOrderExt::findOne(['order_id' => $id]);
- $order_ext->user_revoke_reason = $status;
- if (!$order_ext->save()) {
- throw new \Exception('保存失败');
- }
- $order_ = Order::findOne($id);
- if ($order['status_ext'] === 5) {
- $order_->trade_status = Order::ORDER_FLOW_CANCEL;
- $msg = '取消成功';
- } else {
- $order_->apply_delete = Order::ORDER_APPLY_DELETE;
- $msg = '申请成功';
- }
- if (!$order_->save()) {
- throw new \Exception('保存失败');
- }
- return [
- 'code' => 0,
- 'msg' => $msg
- ];
- } catch (\Exception $e) {
- return [
- 'code' => 1,
- 'msg' => $e->getMessage()
- ];
- }
- }
- //评价页面
- public function getOrderGoodsInfo() {
- try {
- $id = $this->id;
- $goods_id = $this->goods_ids;
- $store_id = $this->store_id;
- if (!$goods_id) {
- throw new \Exception('缺失必要参数');
- }
- $goods_id = explode(',', $goods_id);
- $goods_id = array_merge($goods_id, [0]);
- $comment_order_detail_id = OrderComment::find()->where(['order_id' => $id])->select('order_detail_id')->column();
- $list = OrderDetail::find()->alias('od')->where(['od.order_id' => $id, 'od.goods_id' => $goods_id])
- ->andWhere(['NOT IN', 'od.id', $comment_order_detail_id])
- ->leftJoin(['o' => Order::tableName()], 'od.order_id = o.id')
- ->leftJoin(['woe' => WorkerOrderExt::tableName()], 'woe.order_id = od.order_id')
- ->leftJoin(['wge' => WorkerGoodsExt::tableName()], 'od.goods_id = wge.goods_id')
- ->select('od.id, od.goods_id, woe.worker_id, od.goods_name, od.pic goods_pic, od.num, od.total_price, o.book_info, woe.status_ext, wge.payment_type, od.pre_price')
- ->asArray()->all();
- $setting = WorkerSetting::getByStoreId($store_id);
- $tag = [];
- if($setting){
- $tag = $setting->tag ? explode(',', $setting->tag) : [];
- }
- foreach ($list as &$info) {
- if (empty($info)) {
- throw new \Exception('订单信息查询失败');
- }
- $info['tag'] = $tag;
- $info['status'] = -1;
- $info['status_ext'] = (int)$info['status_ext'];
- if (in_array($info['status_ext'], [10, 15, 20, 30, 40])) {
- $info['status'] = 0;
- }
- if ($info['status_ext'] === 50) {
- $info['status'] = 1;
- }
- $info['book_info'] = json_decode($info['book_info'], true);
- if ($info['status_ext'] === 100) {
- $info['status'] = OrderComment::findOne(['order_id' => $info['id']]) ? 3 : 2;
- }
- if ($info['status_ext'] === 70) {
- $info['status'] = 4;
- }
- if (intval($info['payment_type']) === 1) {
- $info['price'] = $info['pre_price'];
- } else {
- $info['price'] = $info['total_price'];
- }
- $info['goods_price'] += $info['price'];
- $worker = Worker::findOne($info['worker_id']);
- $info['worker'] = $worker ? [
- 'id' => $worker->id,
- 'name' => $worker->name,
- 'level_name' => WorkerLevel::findOne(['store_id' => $store_id, 'level' => $worker->level])->name ?? '服务人员',
- 'logo' => $worker->logo
- ] : null;
- }
- return [
- 'code' => 0,
- 'msg' => '获取成功',
- 'data' => $list
- ];
- } catch (\Exception $e) {
- return [
- 'code' => 1,
- 'msg' => $e->getMessage()
- ];
- }
- }
- public function getPayType() {
- $pay_type_list_json = Option::get(OptionSetting::STORE_PAYMENT, get_store_id(), 'pay', Option::get(OptionSetting::STORE_PAYMENT, get_store_id(), 'store', '{"wechat":{"value":1}}')['value']);
- $pay_type_list = Json::decode($pay_type_list_json['value']);
- $new_list = [];
- $ok = true;
- $is_virtual = false;
- $is_integral = false; //积分兑换商品
-
- if (is_wechat_platform() || $this->_from == 'app') {
- $new_list[] = [
- 'name' => '微信支付',
- 'payment' => 1,
- 'icon' => \Yii::$app->request->hostInfo . \Yii::$app->request->baseUrl . '/web/v1/statics/images/recharge/icon-online.png'
- ];
- }
- if (is_alipay_platform() || $this->_from == 'app') {
- $new_list[] = [
- 'name' => '支付宝支付',
- 'payment' => 4,
- 'icon' => \Yii::$app->request->hostInfo . \Yii::$app->request->baseUrl . '/web/v1/statics/images/recharge/icon-alipay.png'
- ];
- }
- if (is_toutiao_platform()) {
- $new_list[] = [
- 'name' => '线上支付',
- 'payment' => 5,
- 'icon' => \Yii::$app->request->hostInfo . \Yii::$app->request->baseUrl . '/web/v1/statics/images/recharge/icon-online.png'
- ];
- }
- //积分兑换商品取消这两种支付方式
- if(!$is_integral){
- foreach ($pay_type_list as $index => $value) {
- if ($index == 'huodao' && $value['value'] == 1 && $ok && !$is_virtual) {
- $new_list[] = [
- 'name' => '货到付款',
- 'payment' => 2,
- 'icon' => \Yii::$app->request->hostInfo . \Yii::$app->request->baseUrl . '/web/v1/statics/images/recharge/icon-huodao.png'
- ];
- }
- if ($index == 'friend' && $value['value'] == 1) {
- $new_list[] = [
- 'name' => '朋友代付',
- 'payment' => 7,
- 'icon' => \Yii::$app->request->hostInfo . \Yii::$app->request->baseUrl . '/web/v1/statics/images/recharge/icon-huodao.png'
- ];
- }
- }
- }
- foreach ($pay_type_list as $index => $value) {
- if ((is_app_platform() || is_wechat_platform()) && $index == Order::PAY_TYPE_KEY_ADAPAY_WX && $value['value'] == 1) {
- $new_list[] = [
- 'name' => Order::PAY_TYPE_NAME_ADAPAY_WX,
- 'payment' => Order::PAY_TYPE_ADAPAY_WX,
- 'icon' => \Yii::$app->request->hostInfo . \Yii::$app->request->baseUrl . '/web/v1/statics/images/recharge/icon-online.png'
- ];
- }
- if ((is_app_platform() || is_alipay_platform()) && $index == Order::PAY_TYPE_KEY_ADAPAY_ALIPAY && $value['value'] == 1) {
- $new_list[] = [
- 'name' => Order::PAY_TYPE_NAME_ADAPAY_ALIPAY,
- 'payment' => Order::PAY_TYPE_ADAPAY_ALIPAY,
- 'icon' => \Yii::$app->request->hostInfo . \Yii::$app->request->baseUrl . '/web/v1/statics/images/recharge/icon-alipay.png'
- ];
- }
- if ($index == Order::PAY_TYPE_KEY_ADAPAY_QUICKPAY_FRONTPAY && $value['value'] == 1) {
- $new_list[] = [
- 'name' => Order::PAY_TYPE_NAME_ADAPAY_QUICKPAY_FRONTPAY,
- 'payment' => Order::PAY_TYPE_ADAPAY_QUICKPAY_FRONTPAY,
- 'icon' => \Yii::$app->request->hostInfo . \Yii::$app->request->baseUrl . '/web/v1/statics/images/recharge/icon-alipay.png'
- ];
- }
- if ((is_wechat_platform()) && $index == Order::PAY_TYPE_KEY_HUIFU_V2_JSPAY_WX && $value['value'] == 1) {
- $new_list[] = [
- 'name' => Order::PAY_TYPE_NAME_HUIFU_V2_JSPAY_WX,
- 'payment' => Order::PAY_TYPE_HUIFU_V2_JSPAY_WX,
- 'icon' => \Yii::$app->request->hostInfo . \Yii::$app->request->baseUrl . '/web/v1/statics/images/recharge/icon-alipay.png'
- ];
- }
- }
- return $new_list;
- }
- public function distance($distance)
- {
- if ($distance == -1) {
- return -1;
- }
- if ($distance > 1000) {
- $distance = round($distance / 1000, 2) . 'km';
- } else {
- $distance = round($distance, 2);
- $distance .= 'm';
- }
- return $distance;
- }
-
- public static function orderFinishPay($worker_id = 0, $order_id = 0, $fee = 0) {
- $t = \Yii::$app->db->beginTransaction();
- try{
- $typeExt = Order::ORDER_TYPE_EXT_WORKER_LAST_PAY;
- $has = Order::findOne(['base_order_id' => $order_id, 'order_type_ext' => $typeExt, 'is_delete' => 0]);
- if($has){
- throw new \Exception('尾款订单已存在');
- }
- $order = Order::findOne($order_id);
- $orderExt = WorkerOrderExt::findOne(['order_id' => $order_id]);
- if($orderExt['worker_id'] != $worker_id){
- throw new \Exception('服务人员错误');
- }
- $attrCopy = [
- 'store_id', 'user_id', 'saas_id', 'name', 'mobile', 'address', 'address_data', 'version', 'order_type', 'book_info',
- 'province_id', 'city_id', 'district_id',
- ];
- $orderNew = new Order();
- foreach($attrCopy as $attr){
- $orderNew->setAttribute($attr, $order[$attr]);
- }
- $orderNew->base_order_id = $order_id;
- $orderNew->order_no = $order['order_no'] . 'E' . $typeExt;
- $orderNew->first_price = 0;
- $orderNew->second_price = 0;
- $orderNew->third_price = 0;
- $orderNew->pay_price = $fee;
- $orderNew->total_price = $fee;
- $orderNew->order_type = Order::ORDER_TYPE_WORKER;
- $orderNew->order_type_ext = $typeExt;
- $orderNew->created_at = time();
- $save = $orderNew->save();
- if(!$save){
- throw new \Exception('保存订单失败' . array_shift($orderNew->getFirstErrors()));
- }
-
- $attrOdCopy = [
- 'goods_id', 'goods_name', 'num', 'total_price', 'attr', 'pic', 'goods_info',
- ];
- $goods_name = '';
- $od = $order->detail;
- foreach ($od as $d) {
- $goods_name = $d['goods_name'];
- $odNew = new OrderDetail();
- foreach($attrOdCopy as $attr){
- $odNew->setAttribute($attr, $d[$attr]);
- }
- $odNew->order_id = $orderNew->id;
- $save = $odNew->save();
- if(!$save){
- throw new \Exception('保存订单商品失败' . array_shift($odNew->getFirstErrors()));
- }
- }
-
- $attrExtCopy = [
- 'worker_id', 'lat', 'lng'
- ];
- $orderExtNew = WorkerOrderExt::findOne(['order_id' => $orderNew->id]);
- foreach($attrExtCopy as $attr){
- $orderExtNew->setAttribute($attr, $orderExt[$attr]);
- }
- $save = $orderExtNew->save();
- if(!$save){
- throw new \Exception('保存订单扩展信息失败' . array_shift($orderExtNew->getFirstErrors()));
- }
- $t->commit();
- // 订单提交完成发送消息
- NoticeSend::OrderSubmit($orderNew->user_id, $orderNew->mobile, $orderNew->order_no, $orderNew->pay_price, $goods_name, $orderNew->order_type, $orderNew->store_id);
- return [
- 'code' => 0,
- 'msg' => 'ok',
- ];
- } catch (\Exception $ex) {
- $t->rollback();
- return [
- 'code' => 1,
- 'msg' => '创建尾款订单失败,' . $ex->getMessage(),
- ];
- }
- }
-
- public static function orderAddTime($worker_id = 0, $order_id = 0, $fee = 0, $goodsCount = 0) {
- $t = \Yii::$app->db->beginTransaction();
- try{
- $typeExt = Order::ORDER_TYPE_EXT_WORKER_ADD_TIME;
- $has = Order::findOne(['AND', ['base_order_id' => $order_id, 'order_type_ext' => $typeExt, 'is_delete' => 0], ['<>', 'trade_status', 1]]);
- if($has->id){
- throw new \Exception('加钟订单已存在');
- }
- $order = Order::findOne($order_id);
- $orderExt = WorkerOrderExt::findOne(['order_id' => $order_id]);
- if($orderExt['worker_id'] != $worker_id){
- throw new \Exception('服务人员错误');
- }
- if($goodsCount){
- $od = $order->detail;
- foreach ($od as $d) {
- $fee += $d['total_price'] / $d['num'] * $goodsCount;
- }
- }
- $attrCopy = [
- 'store_id', 'user_id', 'saas_id', 'name', 'mobile', 'address', 'address_data', 'version', 'order_type', 'book_info',
- 'province_id', 'city_id', 'district_id',
- ];
- $orderNew = new Order();
- foreach($attrCopy as $attr){
- $orderNew->setAttribute($attr, $order[$attr]);
- }
- $orderNew->base_order_id = $order_id;
- $orderNew->order_no = $order['order_no'] . 'E' . $typeExt;
- $orderNew->first_price = 0;
- $orderNew->second_price = 0;
- $orderNew->third_price = 0;
- $orderNew->pay_price = $fee;
- $orderNew->total_price = $fee;
- $orderNew->order_type = Order::ORDER_TYPE_WORKER;
- $orderNew->order_type_ext = $typeExt;
- $orderNew->created_at = time();
- $save = $orderNew->save();
- if(!$save){
- throw new \Exception('保存订单失败' . array_shift($orderNew->getFirstErrors()));
- }
-
- $attrOdCopy = [
- 'goods_id', 'goods_name', 'num', 'total_price', 'attr', 'pic', 'goods_info',
- ];
- $goods_name = '';
- $od = $order->detail;
- foreach ($od as $d) {
- $goods_name = $d['goods_name'];
- $odNew = new OrderDetail();
- foreach($attrOdCopy as $attr){
- $odNew->setAttribute($attr, $d[$attr]);
- }
- $odNew->order_id = $orderNew->id;
- $save = $odNew->save();
- if(!$save){
- throw new \Exception('保存订单商品失败' . array_shift($odNew->getFirstErrors()));
- }
- }
-
- $attrExtCopy = [
- 'worker_id', 'lat', 'lng'
- ];
- $orderExtNew = WorkerOrderExt::findOne(['order_id' => $orderNew->id]);
- foreach($attrExtCopy as $attr){
- $orderExtNew->setAttribute($attr, $orderExt[$attr]);
- }
- $save = $orderExtNew->save();
- if(!$save){
- throw new \Exception('保存订单扩展信息失败' . array_shift($orderExtNew->getFirstErrors()));
- }
- $t->commit();
- // 订单提交完成发送消息
- NoticeSend::OrderSubmit($orderNew->user_id, $orderNew->mobile, $orderNew->order_no, $orderNew->pay_price, $goods_name, $orderNew->order_type, $orderNew->store_id);
- return [
- 'code' => 0,
- 'msg' => 'ok',
- ];
- } catch (\Exception $ex) {
- $t->rollback();
- return [
- 'code' => 1,
- 'msg' => '创建加钟订单失败,' . $ex->getMessage(),
- ];
- }
- }
- }
|