OrderForm.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588
  1. <?php
  2. namespace common\models\forms;
  3. use common\helpers\Cache;
  4. use common\helpers\Date;
  5. use common\components\Model;
  6. use common\helpers\Form;
  7. use common\helpers\user\Balance;
  8. use common\helpers\user\Cash;
  9. use common\helpers\user\Info;
  10. use common\libs\logging\operate\AdminOperate;
  11. use common\models\DealType;
  12. use common\models\Order;
  13. use common\models\OrderGoods;
  14. use common\models\Period;
  15. use common\models\ReceiveAddress;
  16. use common\models\Region;
  17. use common\models\ShopGoods;
  18. use common\models\User;
  19. use common\models\UserNetwork;
  20. use yii\base\Exception;
  21. /**
  22. * Login form
  23. */
  24. class OrderForm extends Model
  25. {
  26. public $sn;
  27. public $expressCompany;
  28. public $orderTrackNo;
  29. public $status;
  30. public $remark;
  31. public $type;
  32. public $addressId;
  33. public $payType;
  34. public $goodsId;
  35. public $goodsNum;
  36. public $payPassword;
  37. public $userName;
  38. public $consignee;
  39. public $acceptMobile;
  40. public $province;
  41. public $city;
  42. public $county;
  43. public $detailaddress;
  44. private $_address;
  45. private $_decAmount;
  46. private $_decPv;
  47. private $_freight;
  48. private $_payAmount;
  49. private $_orderGoods;
  50. /**
  51. * @var Order
  52. */
  53. private $_model;
  54. public function init() {
  55. parent::init();
  56. $this->adminOperateLogger = new AdminOperate([
  57. 'fetchClass' => Order::class,
  58. ]);
  59. }
  60. /**
  61. * @inheritdoc
  62. */
  63. public function rules()
  64. {
  65. return [
  66. [['sn', 'expressCompany', 'orderTrackNo', 'status', 'remark','type','addressId','payType','goodsId','goodsNum', 'payPassword','userName','consignee','acceptMobile','province','city','county','detailaddress'], 'trim'],
  67. [['sn', 'expressCompany', 'orderTrackNo', 'status', 'remark','type','addressId','payType','goodsId','goodsNum', 'payPassword','userName','consignee','acceptMobile','province','city','county','detailaddress'], 'required'],
  68. [['status'], 'isStatus'],
  69. [['addressId'], 'isAddress'],
  70. [['payType'], 'isPayType'],
  71. [['payPassword'], 'validatePassword'],
  72. ];
  73. }
  74. public function attributeLabels()
  75. {
  76. return [
  77. 'sn' => '订单号',
  78. 'expressCompany' => '快递公司',
  79. 'orderTrackNo' => '快递单号',
  80. 'status' => '状态',
  81. 'remark' => '备注',
  82. 'type' => '订单类型',
  83. 'addressId' => '收货地址',
  84. 'payType' => '支付方式',
  85. 'goodsId' => '商品ID',
  86. 'goodsNum' => '商品数量',
  87. 'userName' => '复消会员编号',
  88. 'consignee' => '收货人',
  89. 'acceptMobile' => '收货电话',
  90. 'province' => '省',
  91. 'city' => '市',
  92. 'county' => '区',
  93. 'detailaddress' => '收货详细地址',
  94. ];
  95. }
  96. /**
  97. * 指定校验场景
  98. * @return array
  99. */
  100. public function scenarios()
  101. {
  102. $parentScenarios = parent::scenarios();
  103. $customScenarios = [
  104. // 管理员发货
  105. 'adminDelivery' => ['sn', 'expressCompany', 'orderTrackNo'],
  106. // 会员确认收货
  107. 'userConfirm' => ['sn', 'expressCompany', 'orderTrackNo'],
  108. // 管理员修改订单状态
  109. 'adminStatus' => ['sn', 'status'],
  110. // 管理员修改备注
  111. 'adminRemark' => ['sn', 'remark'],
  112. // 会员下单
  113. 'userOrder' => ['type','addressId', 'payType','goodsId','goodsNum', 'remark', 'payPassword'],
  114. // 帮会员复消下单
  115. 'reconsumeOrder' => ['type','userName', 'payType','goodsId','goodsNum', 'remark', 'payPassword','consignee','acceptMobile','province','city','county','detailaddress'],
  116. ];
  117. return array_merge($parentScenarios, $customScenarios);
  118. }
  119. /**
  120. * 校验之前
  121. * @return bool
  122. */
  123. public function beforeValidate()
  124. {
  125. $parentValidate = parent::beforeValidate();
  126. if ($this->sn) {
  127. $this->_model = Order::findOne(['SN'=>$this->sn]);
  128. if (!$this->_model){
  129. $this->addError('sn', '订单不存在');
  130. return false;
  131. }
  132. }
  133. if ($this->scenario == 'adminDelivery'){
  134. if($this->_model['STATUS'] == \Yii::$app->params['orderStatus']['cancel']) {
  135. $this->addError('sn', '订单已取消不能发货');
  136. return false;
  137. }
  138. if($this->_model['STATUS'] == \Yii::$app->params['orderStatus']['del']) {
  139. $this->addError('sn', '订单已删除不能发货');
  140. return false;
  141. }
  142. }
  143. return $parentValidate;
  144. }
  145. /**
  146. * 校验支付密码
  147. * @param $attribute
  148. * @param $params
  149. */
  150. public function validatePassword($attribute, $params) {
  151. if (!User::validatePayPassword(\Yii::$app->user->id, $this->payPassword)) {
  152. $this->addError($attribute, '支付密码不正确');
  153. }
  154. }
  155. /**
  156. * 判断收货地址是否存在
  157. * @param $attribute
  158. */
  159. public function isAddress($attribute){
  160. if (!$receiveAddress = ReceiveAddress::find()->where(' ID=:ID', [':ID' => $this->addressId])->asArray()->one()) {
  161. $this->addError($attribute, '收货地址不存在');
  162. } else {
  163. $this->_address = $receiveAddress;
  164. }
  165. }
  166. /**
  167. * 判断支付方式
  168. * @param $attribute
  169. */
  170. public function isPayType($attribute){
  171. if(!array_key_exists($this->payType, ShopGoods::payTypes())){
  172. $this->addError($attribute, '支付方式错误');
  173. return;
  174. }
  175. }
  176. /**
  177. * 校验类型
  178. * @param $attribute
  179. */
  180. public function isStatus($attribute){
  181. if(!in_array($this->type, \Yii::$app->params['orderStatus'])){
  182. $this->addError($attribute, '类型错误');
  183. return ;
  184. }
  185. if ($this->scenario == 'adminStatus'){
  186. if ($this->status == $this->_model['STATUS']) {
  187. $this->addError($attribute, '订单状态没有改变');
  188. return ;
  189. }
  190. if($this->status == \Yii::$app->params['orderStatus']['notPaid'] && $this->_model['STATUS'] >= \Yii::$app->params['orderStatus']['delivery']) {
  191. $this->addError($attribute, '订单已经进入物流状态不能改为未支付');
  192. return ;
  193. }
  194. elseif($this->status == \Yii::$app->params['orderStatus']['paid'] && $this->_model['STATUS'] >= \Yii::$app->params['orderStatus']['cancel']) {
  195. $this->addError($attribute, '订单已失效不能处理');
  196. return ;
  197. }
  198. elseif($this->status == \Yii::$app->params['orderStatus']['delivery']) {
  199. $this->addError($attribute, '订单不能单独处理为物流状态');
  200. return ;
  201. }
  202. elseif($this->status == \Yii::$app->params['orderStatus']['complete'] && $this->_model['STATUS'] > \Yii::$app->params['orderStatus']['cancel']) {
  203. $this->addError($attribute, '订单已失效不能处理');
  204. return ;
  205. }
  206. elseif($this->status == \Yii::$app->params['orderStatus']['cancel']) {
  207. if($this->_model['STATUS'] == \Yii::$app->params['orderStatus']['complete']) {
  208. $this->addError($attribute, '订单已完成不能取消');
  209. return ;
  210. }
  211. if($this->_model['STATUS'] == \Yii::$app->params['orderStatus']['del']) {
  212. $this->addError($attribute, '订单已删除不能取消');
  213. return ;
  214. }
  215. }
  216. elseif($this->status == \Yii::$app->params['orderStatus']['del']) {
  217. if($this->_model['STATUS'] == \Yii::$app->params['orderStatus']['complete']) {
  218. $this->addError($attribute, '订单已完成不能删除');
  219. return ;
  220. }
  221. }
  222. }
  223. }
  224. /**
  225. * 管理员发货
  226. * @return Order|null
  227. * @throws \yii\db\Exception
  228. */
  229. public function adminDelivery(){
  230. if(!$this->validate()){
  231. return null;
  232. }
  233. $db = \Yii::$app->db;
  234. $transaction = $db->beginTransaction();
  235. try {
  236. $period = Period::instance();
  237. $this->_model->DELIVERY_STATUS = \Yii::$app->params['deliveryStatus']['delivered']['value'];
  238. $this->_model->DELIVERY_PERIOD = $period->getNowPeriodNum();
  239. $this->_model->DELIVERY_AT = Date::nowTime();
  240. $this->_model->EXPRESS_COMPANY = $this->expressCompany;
  241. $this->_model->ORDER_TRACK_NO = $this->orderTrackNo;
  242. $this->_model->STATUS = \Yii::$app->params['orderStatus']['delivery']['value'];
  243. if(!$this->_model->save()){
  244. throw new Exception(Form::formatErrorsForApi($this->_model->getErrors()));
  245. }
  246. $transaction->commit();
  247. } catch (Exception $e) {
  248. $transaction->rollBack();
  249. $this->addError('edit', $e->getMessage());
  250. return null;
  251. }
  252. return $this->_model;
  253. }
  254. /**
  255. * 复销
  256. * @return bool|null
  257. * @throws Exception
  258. * @throws \yii\db\Exception
  259. */
  260. public function add(){
  261. if(!$this->validate()){
  262. return null;
  263. }
  264. $ids = $this->goodsId;
  265. $totalAmount = 0;
  266. $totalPv = 0;
  267. $goodsType = ShopGoods::GOODS_TYPE;
  268. foreach ($this->goodsNum as $k => $v) {
  269. if ($v) {
  270. $goods = ShopGoods::findOneAsArray('ID=:ID AND STATUS=1',[':ID'=> $ids[$k]]);
  271. if($goods['STORE_NUMS']>0){
  272. $discount = $goodsType[$goods['TYPE']]['discount'];
  273. $realPrice = $goods['SELL_PRICE'] * $discount/100;
  274. $realPv = $goods['PRICE_PV'] * $discount/100;
  275. $totalAmount += $realPrice * intval($v);
  276. $totalPv += $realPv * intval($v);
  277. // if($this->payType=='cash') {
  278. // $discount = $goodsType[$goods['TYPE']]['discount'];
  279. // $realPrice = $goods['SELL_PRICE'] * $discount/100;
  280. // $realPv = $goods['PRICE_PV'] * $discount/100;
  281. // $totalAmount += $realPrice * intval($v);
  282. // $totalPv += $realPv * intval($v);
  283. // }else{
  284. // $realPrice = $goods['SELL_PRICE'];
  285. // $realPv = $goods['PRICE_PV'];
  286. // $totalAmount += $realPrice * intval($v);
  287. // $totalPv += $realPv * intval($v);
  288. // }
  289. $this->_orderGoods[] = [
  290. 'GOODS_ID' => $goods['ID'],
  291. 'PRICE' => $goods['SELL_PRICE'],
  292. 'PV' => $goods['PRICE_PV'],
  293. 'REAL_PRICE' => $realPrice,
  294. 'REAL_PV' => $realPv,
  295. 'POINT' => $goods['POINT'],
  296. 'BUY_NUMS' => intval($v),
  297. 'SKU_CODE' => $goods['GOODS_NO'],
  298. 'GOODS_TITLE' => $goods['GOODS_NAME']
  299. ];
  300. }
  301. }
  302. }
  303. $this->_decAmount = $totalAmount;
  304. $this->_decPv = $totalPv;
  305. $this->_freight = ($totalAmount>=300) ? 0 : 15;
  306. $this->_payAmount = $this->_decAmount + $this->_freight;
  307. $db = \Yii::$app->db;
  308. $transaction = $db->beginTransaction();
  309. try {
  310. //判断用户余额是否充足
  311. $loginUserId = \Yii::$app->user->id;
  312. if($this->payType=='cash') {
  313. if (Cash::getAvailableBalance($loginUserId) < $this->_payAmount) {
  314. throw new Exception('余额不足,无法购买商品');
  315. }
  316. }else{
  317. if ($this->_payAmount > Balance::getBalanceReconsumePoints($loginUserId)) {
  318. throw new Exception('复消积分不足,无法购买商品');
  319. }
  320. }
  321. //写入订单
  322. if (!$orderResult = $this->addOrder()) {
  323. throw new Exception(Form::formatErrorsForApi($orderResult->getErrors()));
  324. }
  325. $transaction->commit();
  326. }catch (\Exception $e){
  327. $transaction->rollBack();
  328. $this->addError('add', $e->getMessage());
  329. return null;
  330. }
  331. return true;
  332. }
  333. /**
  334. * 复销订单
  335. */
  336. public function addOrder(){
  337. $periodObj = Period::instance();
  338. $nowPeriodNum = $periodObj->getNowPeriodNum();
  339. $nowCalcMonth = $periodObj->getYearMonth($nowPeriodNum);
  340. $userId = \Yii::$app->user->id;
  341. $userName = Info::getUserNameByUserId($userId);
  342. // 加入订单信息
  343. $warehouse = Region::getWarehouseByCode($this->_address['PROVINCE']);//仓库
  344. if(!$warehouse){
  345. throw new Exception('地区暂时不支持配送,具体联系客服');
  346. }
  347. $ordNo = $this->_generateSn();
  348. $orderModel = new Order();
  349. $orderModel->SN = 'OS'.$ordNo;
  350. $orderModel->DEC_SN = 'DS'.$ordNo;
  351. $orderModel->ORDER_TYPE = $this->type;
  352. $orderModel->USER_ID = $userId;
  353. $orderModel->USER_NAME = $userName;
  354. $orderModel->ORDER_AMOUNT = $this->_decAmount;
  355. $orderModel->PV = $this->_decPv;
  356. $orderModel->PAY_AMOUNT = $this->_payAmount;
  357. $orderModel->PAY_PV = $this->_decPv;
  358. $orderModel->PAY_AT = Date::nowTime();
  359. $orderModel->PAY_TYPE = $this->payType;
  360. $orderModel->PERIOD_NUM = $nowPeriodNum;
  361. $orderModel->P_CALC_MONTH = Date::ociToDate($nowCalcMonth, Date::OCI_TIME_FORMAT_SHORT_MONTH);
  362. $orderModel->FREIGHT = $this->_freight;
  363. $orderModel->PAY_FREIGHT = $this->_freight;
  364. $orderModel->CONSIGNEE = $this->_address['CONSIGNEE'];
  365. $orderModel->MOBILE = $this->_address['MOBILE'];
  366. $orderModel->PROVINCE = $this->_address['PROVINCE'];
  367. $orderModel->CITY = $this->_address['CITY'];
  368. $orderModel->COUNTY = $this->_address['COUNTY'];
  369. $orderModel->ADDRESS = $this->_address['ADDRESS'];
  370. $orderModel->FRONT_REMARK = $this->remark;
  371. $orderModel->WAREHOUSE = $warehouse;
  372. $orderModel->STATUS = 1;
  373. $orderModel->CREATED_AT = Date::nowTime();
  374. $orderModel->CREATE_USER = $userName;
  375. if(!$orderModel->save()){
  376. $this->addErrors($orderModel->getErrors());
  377. return false;
  378. }
  379. // 加入商品到订单商品表
  380. foreach($this->_orderGoods as $key=>$value){
  381. $this->_orderGoods[$key]['ORDER_SN'] = $orderModel->SN;
  382. $this->_orderGoods[$key]['P_CALC_MONTH'] = Date::ociToDate($nowCalcMonth, Date::OCI_TIME_FORMAT_SHORT_MONTH);
  383. }
  384. OrderGoods::batchInsert($this->_orderGoods);
  385. //扣除会员余额/积分
  386. if($this->payType=='cash') {
  387. Cash::changeUserCash(\Yii::$app->user->id, 'CASH', -abs($this->_payAmount), ['REMARK' => '会员复销余额支付']);
  388. }else{
  389. Balance::changeUserBonus(\Yii::$app->user->id,'reconsume_points', -abs($this->_payAmount),['DEAL_TYPE_ID' => DealType::RECONSUME_POINTS_EXCHANGE,'REMARK' => '会员复销积分兑换']);
  390. }
  391. return $orderModel;
  392. }
  393. /**
  394. * 帮会员复销
  395. * @return bool|null
  396. * @throws Exception
  397. * @throws \yii\db\Exception
  398. */
  399. public function reconsumeAdd(){
  400. if(!$this->validate()){
  401. return null;
  402. }
  403. $ids = $this->goodsId;
  404. $totalAmount = 0;
  405. $totalPv = 0;
  406. $goodsType = ShopGoods::GOODS_TYPE;
  407. foreach ($this->goodsNum as $k => $v) {
  408. if ($v) {
  409. $goods = ShopGoods::findOneAsArray('ID=:ID AND STATUS=1',[':ID'=> $ids[$k]]);
  410. if($goods['STORE_NUMS']>0){
  411. $discount = $goodsType[$goods['TYPE']]['discount'];
  412. $realPrice = $goods['SELL_PRICE'] * $discount/100;
  413. $realPv = $goods['PRICE_PV'] * $discount/100;
  414. $totalAmount += $realPrice * intval($v);
  415. $totalPv += $realPv * intval($v);
  416. $this->_orderGoods[] = [
  417. 'GOODS_ID' => $goods['ID'],
  418. 'PRICE' => $goods['SELL_PRICE'],
  419. 'PV' => $goods['PRICE_PV'],
  420. 'REAL_PRICE' => $realPrice,
  421. 'REAL_PV' => $realPv,
  422. 'POINT' => $goods['POINT'],
  423. 'BUY_NUMS' => intval($v),
  424. 'SKU_CODE' => $goods['GOODS_NO'],
  425. 'GOODS_TITLE' => $goods['GOODS_NAME']
  426. ];
  427. }
  428. }
  429. }
  430. $this->_decAmount = $totalAmount;
  431. $this->_decPv = $totalPv;
  432. $this->_freight = ($totalAmount>=300) ? 0 : 15;
  433. $this->_payAmount = $this->_decAmount + $this->_freight;
  434. $db = \Yii::$app->db;
  435. $transaction = $db->beginTransaction();
  436. try {
  437. $loginUserId = \Yii::$app->user->id;
  438. //是否开启伞下会员限制
  439. $isResaleUmbrella = Cache::getSystemConfig()['isResaleUmbrella']['VALUE'];
  440. if($isResaleUmbrella){
  441. $userId = Info::getUserIdByUserName($this->userName);
  442. $userNetwork = UserNetwork::find()->where("USER_ID=:USER_ID AND INSTR(PARENT_UIDS,'{$loginUserId}')>0", ['USER_ID'=>$userId])->count();
  443. if(!$userNetwork){
  444. throw new Exception($this->userName.'不是您的伞下会员,不能为其复消!');
  445. }
  446. }
  447. //判断用户余额是否充足
  448. if($this->payType=='cash') {
  449. if (Cash::getAvailableBalance($loginUserId) < $this->_payAmount) {
  450. throw new Exception('余额不足,无法购买商品');
  451. }
  452. }else{
  453. if ($this->_payAmount > Balance::getBalanceReconsumePoints($loginUserId)) {
  454. throw new Exception('复消积分不足,无法购买商品');
  455. }
  456. }
  457. //写入订单
  458. if (!$orderResult = $this->addUserOrder()) {
  459. throw new Exception(Form::formatErrorsForApi($orderResult->getErrors()));
  460. }
  461. $transaction->commit();
  462. }catch (\Exception $e){
  463. $transaction->rollBack();
  464. $this->addError('add', $e->getMessage());
  465. return null;
  466. }
  467. return true;
  468. }
  469. /**
  470. * 帮会员复消的订单
  471. */
  472. public function addUserOrder(){
  473. $periodObj = Period::instance();
  474. $nowPeriodNum = $periodObj->getNowPeriodNum();
  475. $nowCalcMonth = $periodObj->getYearMonth($nowPeriodNum);
  476. //帮复消会员Id(登陆会员)
  477. $loginUserId = \Yii::$app->user->id;
  478. $loginUserName = Info::getUserNameByUserId($loginUserId);
  479. //订单会员Id
  480. $userId = Info::getUserIdByUserName($this->userName);
  481. // 加入订单信息
  482. $warehouse = Region::getWarehouseByCode($this->province);//仓库
  483. if(!$warehouse){
  484. throw new Exception('地区暂时不支持配送,具体联系客服');
  485. }
  486. $ordNo = $this->_generateSn();
  487. $orderModel = new Order();
  488. $orderModel->SN = 'OS'.$ordNo;
  489. $orderModel->DEC_SN = 'DS'.$ordNo;
  490. $orderModel->ORDER_TYPE = $this->type;
  491. $orderModel->USER_ID = $userId;
  492. $orderModel->USER_NAME = $this->userName;
  493. $orderModel->ORDER_AMOUNT = $this->_decAmount;
  494. $orderModel->PV = $this->_decPv;
  495. $orderModel->PAY_AMOUNT = $this->_payAmount;
  496. $orderModel->PAY_PV = $this->_decPv;
  497. $orderModel->PAY_AT = Date::nowTime();
  498. $orderModel->PAY_TYPE = $this->payType;
  499. $orderModel->PERIOD_NUM = $nowPeriodNum;
  500. $orderModel->P_CALC_MONTH = Date::ociToDate($nowCalcMonth, Date::OCI_TIME_FORMAT_SHORT_MONTH);
  501. $orderModel->FREIGHT = $this->_freight;
  502. $orderModel->PAY_FREIGHT = $this->_freight;
  503. $orderModel->CONSIGNEE = $this->consignee;
  504. $orderModel->MOBILE = $this->acceptMobile;
  505. $orderModel->PROVINCE = $this->province;
  506. $orderModel->CITY = $this->city;
  507. $orderModel->COUNTY = $this->county;
  508. $orderModel->ADDRESS = $this->detailaddress;
  509. $orderModel->FRONT_REMARK = $this->remark;
  510. $orderModel->WAREHOUSE = $warehouse;
  511. $orderModel->STATUS = 1;
  512. $orderModel->CREATED_AT = Date::nowTime();
  513. $orderModel->CREATE_USER = $loginUserName;
  514. if(!$orderModel->save()){
  515. $this->addErrors($orderModel->getErrors());
  516. return false;
  517. }
  518. // 加入商品到订单商品表
  519. foreach($this->_orderGoods as $key=>$value){
  520. $this->_orderGoods[$key]['ORDER_SN'] = $orderModel->SN;
  521. $this->_orderGoods[$key]['P_CALC_MONTH'] = Date::ociToDate($nowCalcMonth, Date::OCI_TIME_FORMAT_SHORT_MONTH);
  522. }
  523. OrderGoods::batchInsert($this->_orderGoods);
  524. //扣除会员余额/积分
  525. if($this->payType=='cash') {
  526. Cash::changeUserCash($loginUserId, 'CASH', -abs($this->_payAmount), ['REMARK' => '会员复销余额支付']);
  527. }else{
  528. Balance::changeUserBonus($loginUserId,'reconsume_points', -abs($this->_payAmount),['DEAL_TYPE_ID' => DealType::RECONSUME_POINTS_EXCHANGE, 'REMARK' => '会员复销积分兑换']);
  529. }
  530. return $orderModel;
  531. }
  532. /**
  533. * 生成流水号
  534. * @return string
  535. */
  536. private function _generateSn() {
  537. return Date::today('Ymd') . $this->_random(10, 1);
  538. }
  539. /**
  540. * 生成随机数
  541. * @param $length
  542. * @param int $numeric
  543. * @return string
  544. */
  545. private function _random($length, $numeric = 0) {
  546. $seed = base_convert(md5(microtime() . $_SERVER['DOCUMENT_ROOT']), 16, $numeric ? 10 : 35);
  547. $seed = $numeric ? (str_replace('0', '', $seed) . '012340567890') : ($seed . 'zZ' . strtoupper($seed));
  548. $hash = '';
  549. $max = strlen($seed) - 1;
  550. for ($i = 0; $i < $length; $i++) {
  551. $hash .= $seed[mt_rand(0, $max)];
  552. }
  553. return $hash;
  554. }
  555. }