| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026 |
- <?php
- /**
- * 重庆赤晓店信息科技有限公司
- * https://www.chixiaodian.com
- * Copyright (c) 2023 赤店商城 All rights reserved.
- */
- namespace app\modules\admin\models\pospal;
- use app\models\Option;
- use app\constants\OptionSetting;
- use app\models\AccountLog;
- use app\models\User;
- use app\models\SaasUser;
- use app\models\Cat;
- use app\models\Goods;
- use app\models\Attr;
- use app\models\AttrGroup;
- use app\modules\admin\models\GoodsForm;
- use app\models\GoodsCat;
- use app\models\Order;
- use app\models\OrderDetail;
- use app\models\OrderPospal;
- use app\models\OrderPospalDetail;
- use app\models\PospalCat;
- use app\models\PospalGoods;
- use app\models\PospalUser;
- use app\models\PospalOrder;
- use app\models\Store;
- use app\utils\pospal\Api;
- use app\models\common\CommonOrder;
- use app\modules\client\models\v1\BindForm;
- use app\modules\client\models\v1\ShareMoneyForm;
- use app\modules\client\models\OrderComplete;
- use app\models\UserShareLog;
- use app\models\Share;
- use app\models\UserShareMoney;
- use app\models\UserBindLog;
- use app\models\Level;
- class PospalForm extends Model
- {
- public $hostInfo;
- public $store_id;
- public $sync_stock_uids = [];
-
- public static function isopen($store_id = 0) {
- $appkey = Api::appkey($store_id);
- return empty($appkey) ? 0 : 1;
- }
- public function pGoodsList($param = []) {
- if($param['barcode']){
- $list = Api::queryProductByBarcode($this->store_id, $param['barcode']);
- return $list;
- }
- $list = Api::queryProductPages($this->store_id, $param);
- return $list;
- }
- public function pUserList($param = []) {
- $list = Api::queryCustomerPages($this->store_id, $param);
- return $list;
- }
- public function getSyncCache($key) {
- return Option::get($key, $this->store_id, 'store')['value'];
- }
- public function setSyncCache($key, $val) {
- return Option::set($key, $val, $this->store_id, 'store');
- }
- public function orderNotify($order){
- if(!self::isopen($this->store_id)){
- return;
- }
- return $this->syncOrder2Yinbao($order->id);
- }
- public function afterGoodsSave($goods, $changedAttributes){
- if(!self::isopen($this->store_id)){
- return;
- }
- return $this->syncGoods2Yinbao($goods->id, $changedAttributes);
- }
- public function afterUserSave($user){
- if(!self::isopen($this->store_id)){
- return;
- }
- return $this->syncUser2Yinbao($user->id);
- }
- public function needSyncStockUidsYb() {
- $orderIdMax = intval($this->getSyncCache(OptionSetting::POSPAL_SYNC_STOCK_YB_ORDERID_MAX));
- $query = PospalGoods::find()->alias('pg');
- $query->leftJoin(['od' => OrderPospalDetail::tableName()], 'pg.goods_id = od.goods_id');
- $query->leftJoin(['o' => OrderPospal::tableName()], 'o.id = od.order_id');
- $query->andWhere(['>', 'o.id', $orderIdMax]);
- $res = $query->select('o.id orderid, pg.goods_id, pg.productUid')->groupBy('goods_id')->orderBy('orderid ASC')->asArray()->all();
- return $res;
- }
- public function needSyncStockUids() {
- $orderIdMax = intval($this->getSyncCache(OptionSetting::POSPAL_SYNC_STOCK_ORDERID_MAX));
- $query = PospalGoods::find()->alias('pg');
- $query->leftJoin(['od' => OrderDetail::tableName()], 'pg.goods_id = od.goods_id');
- $query->leftJoin(['o' => Order::tableName()], 'o.id = od.order_id');
- $query->andWhere(['>', 'o.id', $orderIdMax]);
- $res = $query->select('o.id orderid, pg.goods_id, pg.productUid')->groupBy('goods_id')->orderBy('orderid ASC')->asArray()->all();
- return $res;
- }
- //从银豹同步订单/减商品库存
- public function syncOrders($param = [], $okCount = 0){
- if(!self::isopen($this->store_id)){
- return;
- }
- set_time_limit(0);
- $i = 0;
- $time = time()-$i*86400;
- empty($param['startTime']) && $param['startTime'] = date('Y-m-d H:i:s', $time - 3600);
- empty($param['endTime']) && $param['endTime'] = date('Y-m-d H:i:s', $time);
- $orders = Api::queryTicketPages($this->store_id, $param);
- // $orders = json_decode('{"status":"success","messages":[],"data":{"postBackParameter":{"parameterType":"LAST_RESULT_MAX_ID","parameterValue":"11047888"},"result":[{"cashierUid":832101480292933201,"cashier":{"jobNumber":"1001","name":"刘本之","uid":832101480292933201},"customerUid":0,"uid":1770095525384431672,"sn":"202305290833048640002","datetime":"2023-05-29 08:33:04","totalAmount":35.00,"totalProfit":6.00,"discount":100.00000,"rounding":0.00,"ticketType":"SELL","invalid":0,"sysUpdateTime":"2023-05-29 08:33:08","externalOrderNo":"4200057841202305291614222138","remark":"","items":[{"id":24715270,"name":"华润五丰寒地东北大米 5kg/袋","buyPrice":29.00000000,"sellPrice":35.00,"customerPrice":35.00,"quantity":1.000,"discount":100.00000,"customerDiscount":100.00,"totalAmount":35.00,"totalProfit":6.00000000,"isCustomerDiscount":1,"productUid":227844485398636082,"productBarcode":"6956056600012","isWeighing":0,"ticketitemattributes":[],"discountDetails":[],"saleGuiderList":[]}],"payments":[{"code":"payCode_-2900","amount":35.00}],"ticketOnTable":{"tableUid":0,"tableAreaUid":0,"tableCardNo":"0002"}},{"cashierUid":832101480292933201,"cashier":{"jobNumber":"1001","name":"刘本之","uid":832101480292933201},"customerUid":0,"uid":1235988339197949796,"sn":"202305290854475270003","datetime":"2023-05-29 08:54:47","totalAmount":2.00,"totalProfit":1.00,"discount":100.00000,"rounding":0.00,"ticketType":"SELL","invalid":0,"sysUpdateTime":"2023-05-29 08:54:51","externalOrderNo":"4200001873202305298027075630","remark":"","items":[{"id":24723579,"name":"农夫山泉天然水550ml/瓶","buyPrice":1.00000000,"sellPrice":2.00,"customerPrice":2.00,"quantity":1.000,"discount":100.00000,"customerDiscount":100.00,"totalAmount":2.00,"totalProfit":1.00000000,"isCustomerDiscount":0,"productUid":126346716668394093,"productBarcode":"6921168509256","isWeighing":0,"ticketitemattributes":[],"discountDetails":[],"saleGuiderList":[]}],"payments":[{"code":"payCode_-2900","amount":2.00}],"ticketOnTable":{"tableUid":0,"tableAreaUid":0,"tableCardNo":"0003"}},{"cashierUid":832101480292933201,"cashier":{"jobNumber":"1001","name":"刘本之","uid":832101480292933201},"customerUid":0,"uid":1503365188614434406,"sn":"202305290907231940004","datetime":"2023-05-29 09:07:23","totalAmount":27.00,"totalProfit":2.80,"discount":100.00000,"rounding":0.00,"ticketType":"SELL","invalid":0,"sysUpdateTime":"2023-05-29 09:07:26","externalOrderNo":"4200001855202305296498929001","remark":"","items":[{"id":24728442,"name":"无码商品","buyPrice":15.00000000,"sellPrice":15.00,"customerPrice":15.00,"quantity":1.000,"discount":100.00000,"customerDiscount":100.00,"totalAmount":15.00,"totalProfit":0E-8,"isCustomerDiscount":0,"productUid":1685322427191116108,"isWeighing":0,"ticketitemattributes":[],"discountDetails":[],"saleGuiderList":[]},{"id":24728443,"name":"统一阿萨姆原味奶茶500ml/瓶","buyPrice":3.20000000,"sellPrice":4.00,"customerPrice":4.00,"quantity":1.000,"discount":100.00000,"customerDiscount":100.00,"totalAmount":4.00,"totalProfit":0.80000000,"isCustomerDiscount":1,"productUid":526311942833963253,"productBarcode":"6925303730574","isWeighing":0,"ticketitemattributes":[],"discountDetails":[],"saleGuiderList":[]},{"id":24728444,"name":"达利园注心巧克力派260g/包","buyPrice":6.00000000,"sellPrice":8.00,"customerPrice":8.00,"quantity":1.000,"discount":100.00000,"customerDiscount":100.00,"totalAmount":8.00,"totalProfit":2.00000000,"isCustomerDiscount":1,"productUid":784071213180411994,"productBarcode":"6911988007209","isWeighing":0,"ticketitemattributes":[],"discountDetails":[],"saleGuiderList":[]}],"payments":[{"code":"payCode_-2900","amount":27.00}],"ticketOnTable":{"tableUid":0,"tableAreaUid":0,"tableCardNo":"0004"}},{"cashierUid":832101480292933201,"cashier":{"jobNumber":"1001","name":"刘本之","uid":832101480292933201},"customerUid":0,"uid":23779605014613706,"sn":"202305290909260730005","datetime":"2023-05-29 09:09:26","totalAmount":8.00,"totalProfit":2.20,"discount":100.00000,"rounding":0.00,"ticketType":"SELL","invalid":0,"sysUpdateTime":"2023-05-29 09:09:29","externalOrderNo":"4200001865202305295299253992","remark":"","items":[{"id":24729320,"name":"康师傅冰红茶柠檬味1L/瓶","buyPrice":2.90000000,"sellPrice":4.00,"customerPrice":4.00,"quantity":2.000,"discount":100.00000,"customerDiscount":100.00,"totalAmount":8.00,"totalProfit":2.20000000,"isCustomerDiscount":1,"productUid":548419923932191655,"productBarcode":"6922456896362","isWeighing":0,"ticketitemattributes":[],"discountDetails":[],"saleGuiderList":[]}],"payments":[{"code":"payCode_-2900","amount":8.00}],"ticketOnTable":{"tableUid":0,"tableAreaUid":0,"tableCardNo":"0005"}},{"cashierUid":832101480292933201,"cashier":{"jobNumber":"1001","name":"刘本之","uid":832101480292933201},"customerUid":0,"uid":86127327725930988,"sn":"202305290920596140006","datetime":"2023-05-29 09:20:59","totalAmount":5.00,"totalProfit":1.40,"discount":100.00000,"rounding":0.00,"ticketType":"SELL","invalid":0,"sysUpdateTime":"2023-05-29 09:21:02","externalOrderNo":"4200001866202305296887452416","remark":"","items":[{"id":24733982,"name":"农夫山泉茶兀蜜桃乌龙茶500ml/瓶","buyPrice":3.60000000,"sellPrice":5.00,"customerPrice":5.00,"quantity":1.000,"discount":100.00000,"customerDiscount":100.00,"totalAmount":5.00,"totalProfit":1.40000000,"isCustomerDiscount":1,"productUid":1122283104413246111,"productBarcode":"6921168593569","isWeighing":0,"ticketitemattributes":[],"discountDetails":[],"saleGuiderList":[]}],"payments":[{"code":"payCode_-2900","amount":5.00}],"ticketOnTable":{"tableUid":0,"tableAreaUid":0,"tableCardNo":"0006"}},{"cashierUid":832101480292933201,"cashier":{"jobNumber":"1001","name":"刘本之","uid":832101480292933201},"customerUid":0,"uid":661507702745965305,"sn":"202305290925457620007","datetime":"2023-05-29 09:25:55","totalAmount":8.00,"totalProfit":1.50,"discount":100.00000,"rounding":0.00,"ticketType":"SELL","invalid":0,"sysUpdateTime":"2023-05-29 09:25:55","remark":"","items":[{"id":24735980,"name":"特仑苏有机纯牛奶250ml/瓶","buyPrice":6.50000000,"sellPrice":8.00,"customerPrice":8.00,"quantity":1.000,"discount":100.00000,"customerDiscount":100.00,"totalAmount":8.00,"totalProfit":1.50000000,"isCustomerDiscount":1,"productUid":265605305856195537,"productBarcode":"6923644285036","isWeighing":0,"ticketitemattributes":[],"discountDetails":[],"saleGuiderList":[]}],"payments":[{"code":"payCode_1","amount":8.00}]},{"cashierUid":832101480292933201,"cashier":{"jobNumber":"1001","name":"刘本之","uid":832101480292933201},"customerUid":0,"uid":118636800949823123,"sn":"202305290933121500008","datetime":"2023-05-29 09:33:12","totalAmount":5.00,"totalProfit":0.50,"discount":100.00000,"rounding":0.00,"ticketType":"SELL","invalid":0,"sysUpdateTime":"2023-05-29 09:33:15","externalOrderNo":"4200059248202305296965753331","remark":"","items":[{"id":24738744,"name":"安慕希风味酸奶205ml(盒)","buyPrice":4.50000000,"sellPrice":5.00,"customerPrice":5.00,"quantity":1.000,"discount":100.00000,"customerDiscount":100.00,"totalAmount":5.00,"totalProfit":0.50000000,"isCustomerDiscount":1,"productUid":939881303174811439,"productBarcode":"6907992512570","isWeighing":0,"ticketitemattributes":[],"discountDetails":[],"saleGuiderList":[]}],"payments":[{"code":"payCode_-2900","amount":5.00}],"ticketOnTable":{"tableUid":0,"tableAreaUid":0,"tableCardNo":"0008"}},{"cashierUid":832101480292933201,"cashier":{"jobNumber":"1001","name":"刘本之","uid":832101480292933201},"customerUid":0,"uid":1347406214677782228,"sn":"202305291006275310009","datetime":"2023-05-29 10:06:28","totalAmount":10.50,"totalProfit":3.30,"discount":100.00000,"rounding":0.00,"ticketType":"SELL","invalid":0,"sysUpdateTime":"2023-05-29 10:06:29","remark":"","items":[{"id":24751584,"name":"晶心低钠盐400g/袋","buyPrice":2.40000000,"sellPrice":3.50,"customerPrice":3.50,"quantity":3.000,"discount":100.00000,"customerDiscount":100.00,"totalAmount":10.50,"totalProfit":3.30000000,"isCustomerDiscount":1,"productUid":814556814232884208,"productBarcode":"6922311001504","isWeighing":0,"ticketitemattributes":[],"discountDetails":[],"saleGuiderList":[]}],"payments":[{"code":"payCode_1","amount":10.50}]},{"cashierUid":832101480292933201,"cashier":{"jobNumber":"1001","name":"刘本之","uid":832101480292933201},"customerUid":0,"uid":214911432762,"sn":"202305291059040850010","datetime":"2023-05-29 10:59:04","totalAmount":4.60,"totalProfit":0.00,"discount":100.00000,"rounding":0.00,"ticketType":"SELL","invalid":0,"sysUpdateTime":"2023-05-29 10:59:08","externalOrderNo":"4200067681202305298808566251","remark":"","items":[{"id":24773449,"name":"无码商品","buyPrice":4.60000000,"sellPrice":4.60,"customerPrice":4.60,"quantity":1.000,"discount":100.00000,"customerDiscount":100.00,"totalAmount":4.60,"totalProfit":0E-8,"isCustomerDiscount":0,"productUid":1685329142464934416,"isWeighing":0,"ticketitemattributes":[],"discountDetails":[],"saleGuiderList":[]}],"payments":[{"code":"payCode_-2900","amount":4.60}],"ticketOnTable":{"tableUid":0,"tableAreaUid":0,"tableCardNo":"0010"}},{"cashierUid":832101480292933201,"cashier":{"jobNumber":"1001","name":"刘本之","uid":832101480292933201},"customerUid":0,"uid":2492415667839217670,"sn":"202305291107522870011","datetime":"2023-05-29 11:07:53","totalAmount":11.00,"totalProfit":0.00,"discount":100.00000,"rounding":0.00,"ticketType":"SELL","invalid":0,"sysUpdateTime":"2023-05-29 11:07:53","remark":"","items":[{"id":24777613,"name":"无码商品","buyPrice":11.00000000,"sellPrice":11.00,"customerPrice":11.00,"quantity":1.000,"discount":100.00000,"customerDiscount":100.00,"totalAmount":11.00,"totalProfit":0E-8,"isCustomerDiscount":0,"productUid":1685329653099465764,"isWeighing":0,"ticketitemattributes":[],"discountDetails":[],"saleGuiderList":[]}],"payments":[{"code":"payCode_1","amount":11.00}]},{"cashierUid":832101480292933201,"cashier":{"jobNumber":"1001","name":"刘本之","uid":832101480292933201},"customerUid":0,"uid":167123812307132400,"sn":"202305291108338330012","datetime":"2023-05-29 11:08:42","totalAmount":49.00,"totalProfit":13.40,"discount":100.00000,"rounding":0.00,"ticketType":"SELL","invalid":0,"sysUpdateTime":"2023-05-29 11:08:42","remark":"","items":[{"id":24778094,"name":"统一阿萨姆奶茶1.5L/瓶","buyPrice":8.60000000,"sellPrice":12.00,"customerPrice":12.00,"quantity":2.000,"discount":100.00000,"customerDiscount":100.00,"totalAmount":24.00,"totalProfit":6.80000000,"isCustomerDiscount":1,"productUid":1031419696635823237,"productBarcode":"6925303739454","isWeighing":0,"ticketitemattributes":[],"discountDetails":[],"saleGuiderList":[]},{"id":24778095,"name":"美年达橙味饮料汽水 2L","buyPrice":5.30000000,"sellPrice":7.00,"customerPrice":7.00,"quantity":2.000,"discount":100.00000,"customerDiscount":100.00,"totalAmount":14.00,"totalProfit":3.40000000,"isCustomerDiscount":1,"productUid":146195606367304196,"productBarcode":"6915766000826","isWeighing":0,"ticketitemattributes":[],"discountDetails":[],"saleGuiderList":[]},{"id":24778096,"name":"雪碧清爽柠檬味饮料2L","buyPrice":5.30000000,"sellPrice":7.00,"customerPrice":7.00,"quantity":1.000,"discount":100.00000,"customerDiscount":100.00,"totalAmount":7.00,"totalProfit":1.70000000,"isCustomerDiscount":1,"productUid":1106265916467625467,"productBarcode":"6954767433073","isWeighing":0,"ticketitemattributes":[],"discountDetails":[],"saleGuiderList":[]},{"id":24778097,"name":"伊利火炬香草口味冰淇淋80克/支","buyPrice":2.50000000,"sellPrice":4.00,"customerPrice":4.00,"quantity":1.000,"discount":100.00000,"customerDiscount":100.00,"totalAmount":4.00,"totalProfit":1.50000000,"isCustomerDiscount":1,"productUid":1121871764110816648,"productBarcode":"6907992822709","isWeighing":0,"ticketitemattributes":[],"discountDetails":[],"saleGuiderList":[]}],"payments":[{"code":"payCode_1","amount":49.00}]},{"cashierUid":832101480292933201,"cashier":{"jobNumber":"1001","name":"刘本之","uid":832101480292933201},"customerUid":0,"uid":669363428927196978,"sn":"202305291110548000013","datetime":"2023-05-29 11:10:54","totalAmount":4.00,"totalProfit":0.80,"discount":100.00000,"rounding":0.00,"ticketType":"SELL","invalid":0,"sysUpdateTime":"2023-05-29 11:10:58","externalOrderNo":"4200067674202305294482565680","remark":"","items":[{"id":24779393,"name":"美汁源果粒奶优菠萝味水果牛奶饮料450g/瓶","buyPrice":3.20000000,"sellPrice":4.00,"customerPrice":4.00,"quantity":1.000,"discount":100.00000,"customerDiscount":100.00,"totalAmount":4.00,"totalProfit":0.80000000,"isCustomerDiscount":0,"productUid":517058333993442949,"productBarcode":"6956416203402","isWeighing":0,"ticketitemattributes":[],"discountDetails":[],"saleGuiderList":[]}],"payments":[{"code":"payCode_-2900","amount":4.00}],"ticketOnTable":{"tableUid":0,"tableAreaUid":0,"tableCardNo":"0013"}},{"cashierUid":832101480292933201,"cashier":{"jobNumber":"1001","name":"刘本之","uid":832101480292933201},"customerUid":0,"uid":249493661972895410,"sn":"202305291114101040014","datetime":"2023-05-29 11:14:11","totalAmount":4.00,"totalProfit":1.60,"discount":100.00000,"rounding":0.00,"ticketType":"SELL","invalid":0,"sysUpdateTime":"2023-05-29 11:14:11","remark":"","items":[{"id":24780908,"name":"晶心中盐加碘食用盐400g/袋","buyPrice":1.20000000,"sellPrice":2.00,"customerPrice":2.00,"quantity":2.000,"discount":100.00000,"customerDiscount":100.00,"totalAmount":4.00,"totalProfit":1.60000000,"isCustomerDiscount":1,"productUid":41831880508985532,"productBarcode":"6922311001306","isWeighing":0,"ticketitemattributes":[],"discountDetails":[],"saleGuiderList":[]}],"payments":[{"code":"payCode_1","amount":4.00}]},{"cashierUid":832101480292933201,"cashier":{"jobNumber":"1001","name":"刘本之","uid":832101480292933201},"customerUid":544496958183373393,"uid":409963322694929892,"sn":"202305291118071410015","datetime":"2023-05-29 11:18:07","totalAmount":4.00,"totalProfit":0.40,"discount":100.00000,"rounding":0.00,"ticketType":"SELL","invalid":0,"sysUpdateTime":"2023-05-29 11:18:09","externalOrderNo":"4200001866202305293576207525","remark":"","items":[{"id":24782901,"name":"雀巢咖啡原味1+2速溶15g/支","buyPrice":1.20000000,"sellPrice":2.00,"customerPrice":2.00,"quantity":3.000,"discount":66.66667,"customerDiscount":100.00,"totalAmount":4.00,"totalProfit":0.40000000,"isCustomerDiscount":1,"productUid":815546838447584211,"productBarcode":"6917878044729","isWeighing":0,"ticketitemattributes":[],"discountDetails":[{"productUid":815546838447584211,"discountType":6,"discountRate":66.66667,"discountAmount":0.66667,"discountRuleUid":0,"discountTotalAmount":2.00,"datetime":"2023-05-29 11:18:07"}],"saleGuiderList":[]}],"payments":[{"code":"payCode_-2900","amount":4.00}],"ticketOnTable":{"tableUid":0,"tableAreaUid":0,"tableCardNo":"0015"}},{"cashierUid":832101480292933201,"cashier":{"jobNumber":"1001","name":"刘本之","uid":832101480292933201},"customerUid":0,"uid":199055072119788256,"sn":"202305291128280100016","datetime":"2023-05-29 11:28:28","totalAmount":2.00,"totalProfit":1.00,"discount":100.00000,"rounding":0.00,"ticketType":"SELL","invalid":0,"sysUpdateTime":"2023-05-29 11:28:31","externalOrderNo":"4200067684202305295693565371","remark":"","items":[{"id":24788274,"name":"怡宝纯净水555ml","buyPrice":1.00000000,"sellPrice":2.00,"customerPrice":2.00,"quantity":1.000,"discount":100.00000,"customerDiscount":100.00,"totalAmount":2.00,"totalProfit":1.00000000,"isCustomerDiscount":1,"productUid":839630792014576874,"productBarcode":"6901285991219","isWeighing":0,"ticketitemattributes":[],"discountDetails":[],"saleGuiderList":[]}],"payments":[{"code":"payCode_-2900","amount":2.00}],"ticketOnTable":{"tableUid":0,"tableAreaUid":0,"tableCardNo":"0016"}},{"cashierUid":832101480292933201,"cashier":{"jobNumber":"1001","name":"刘本之","uid":832101480292933201},"customerUid":0,"uid":686679351800155692,"sn":"202305291129330580017","datetime":"2023-05-29 11:29:33","totalAmount":6.00,"totalProfit":1.50,"discount":100.00000,"rounding":0.00,"ticketType":"SELL","invalid":0,"sysUpdateTime":"2023-05-29 11:29:35","externalOrderNo":"4200059249202305296525946795","remark":"","items":[{"id":24788828,"name":"国药集团积醉解风味饮料240ml/罐","buyPrice":4.50000000,"sellPrice":6.00,"customerPrice":6.00,"quantity":1.000,"discount":100.00000,"customerDiscount":100.00,"totalAmount":6.00,"totalProfit":1.50000000,"isCustomerDiscount":1,"productUid":815609676422751865,"productBarcode":"6971772961452","isWeighing":0,"ticketitemattributes":[],"discountDetails":[],"saleGuiderList":[]}],"payments":[{"code":"payCode_-2900","amount":6.00}],"ticketOnTable":{"tableUid":0,"tableAreaUid":0,"tableCardNo":"0017"}},{"cashierUid":832101480292933201,"cashier":{"jobNumber":"1001","name":"刘本之","uid":832101480292933201},"customerUid":0,"uid":35696205555915267,"sn":"202305291138008170018","datetime":"2023-05-29 11:38:00","totalAmount":100.00,"totalProfit":0.00,"discount":100.00000,"rounding":0.00,"ticketType":"SELL","invalid":0,"sysUpdateTime":"2023-05-29 11:38:04","externalOrderNo":"4200001862202305292893712081","remark":"","items":[{"id":24794054,"name":"无码商品","buyPrice":100.00000000,"sellPrice":100.00,"customerPrice":100.00,"quantity":1.000,"discount":100.00000,"customerDiscount":100.00,"totalAmount":100.00,"totalProfit":0E-8,"isCustomerDiscount":0,"productUid":1685331477808719665,"isWeighing":0,"ticketitemattributes":[],"discountDetails":[],"saleGuiderList":[]}],"payments":[{"code":"payCode_-2900","amount":100.00}],"ticketOnTable":{"tableUid":0,"tableAreaUid":0,"tableCardNo":"0018"}},{"cashierUid":832101480292933201,"cashier":{"jobNumber":"1001","name":"刘本之","uid":832101480292933201},"customerUid":0,"uid":384535591230405433,"sn":"202305291220300480019","datetime":"2023-05-29 12:20:30","totalAmount":4.00,"totalProfit":1.10,"discount":100.00000,"rounding":0.00,"ticketType":"SELL","invalid":0,"sysUpdateTime":"2023-05-29 12:20:35","externalOrderNo":"4200057837202305294713723168","remark":"","items":[{"id":24821913,"name":"百事可乐太汽系列白桃乌龙味500","buyPrice":2.90000000,"sellPrice":4.00,"customerPrice":4.00,"quantity":1.000,"discount":100.00000,"customerDiscount":100.00,"totalAmount":4.00,"totalProfit":1.10000000,"isCustomerDiscount":1,"productUid":46114672084537658,"productBarcode":"6915766005081","isWeighing":0,"ticketitemattributes":[],"discountDetails":[],"saleGuiderList":[]}],"payments":[{"code":"payCode_-2900","amount":4.00}],"ticketOnTable":{"tableUid":0,"tableAreaUid":0,"tableCardNo":"0019"}},{"cashierUid":832101480292933201,"cashier":{"jobNumber":"1001","name":"刘本之","uid":832101480292933201},"customerUid":0,"uid":391467556600875334,"sn":"202305291300270930020","datetime":"2023-05-29 13:00:32","totalAmount":149.97,"totalProfit":51.19,"discount":100.00000,"rounding":0.00,"ticketType":"SELL","invalid":0,"sysUpdateTime":"2023-05-29 13:00:34","remark":"","items":[{"id":24839156,"name":"怡宝纯净水555ml","buyPrice":1.00000000,"sellPrice":2.00,"customerPrice":2.00,"quantity":1.000,"discount":100.00000,"customerDiscount":100.00,"totalAmount":2.00,"totalProfit":1.00000000,"isCustomerDiscount":1,"productUid":839630792014576874,"productBarcode":"6901285991219","isWeighing":0,"ticketitemattributes":[],"discountDetails":[],"saleGuiderList":[]},{"id":24839157,"name":"云南蓝莓葡萄A级","buyPrice":18.00000000,"sellPrice":49.60,"customerPrice":49.60,"quantity":0.920,"discount":100.00000,"customerDiscount":100.00,"totalAmount":45.63,"totalProfit":29.07072581,"isCustomerDiscount":1,"productUid":230287254216269643,"productBarcode":"2211026","isWeighing":1,"ticketitemattributes":[],"discountDetails":[],"saleGuiderList":[]},{"id":24839158,"name":"老挝进口香蕉A级","buyPrice":7.00000000,"sellPrice":11.80,"customerPrice":9.80,"quantity":2.317,"discount":100.00000,"customerDiscount":100.00,"totalAmount":27.34,"totalProfit":11.12135593,"isCustomerDiscount":0,"productUid":352248709527617620,"productBarcode":"2211080","isWeighing":1,"ticketitemattributes":[],"discountDetails":[],"saleGuiderList":[]},{"id":24839159,"name":"伊利安慕希原味酸奶230ml*10/提","buyPrice":65.00000000,"sellPrice":75.00,"customerPrice":75.00,"quantity":1.000,"discount":100.00000,"customerDiscount":100.00,"totalAmount":75.00,"totalProfit":10.00000000,"isCustomerDiscount":1,"productUid":292314413556524364,"productBarcode":"6907992514178","isWeighing":0,"ticketitemattributes":[],"discountDetails":[],"saleGuiderList":[]}],"payments":[{"code":"payCode_1","amount":149.97}]},{"cashierUid":832101480292933201,"cashier":{"jobNumber":"1001","name":"刘本之","uid":832101480292933201},"customerUid":0,"uid":446674388176021810,"sn":"202305291327172450021","datetime":"2023-05-29 13:27:17","totalAmount":1.00,"totalProfit":0.00,"discount":100.00000,"rounding":0.00,"ticketType":"SELL","invalid":0,"sysUpdateTime":"2023-05-29 13:27:21","externalOrderNo":"4200001868202305290516952884","remark":"","items":[{"id":24847850,"name":"无码商品","buyPrice":1.00000000,"sellPrice":1.00,"customerPrice":1.00,"quantity":1.000,"discount":100.00000,"customerDiscount":100.00,"totalAmount":1.00,"totalProfit":0E-8,"isCustomerDiscount":0,"productUid":1685338036123002492,"isWeighing":0,"ticketitemattributes":[],"discountDetails":[],"saleGuiderList":[]}],"payments":[{"code":"payCode_-2900","amount":1.00}],"ticketOnTable":{"tableUid":0,"tableAreaUid":0,"tableCardNo":"0021"}},{"cashierUid":832101480292933201,"cashier":{"jobNumber":"1001","name":"刘本之","uid":832101480292933201},"customerUid":0,"uid":401797095890325341,"sn":"202305291354211290022","datetime":"2023-05-29 13:54:21","totalAmount":28.00,"totalProfit":14.00,"discount":100.00000,"rounding":0.00,"ticketType":"SELL","invalid":0,"sysUpdateTime":"2023-05-29 13:54:25","externalOrderNo":"4200001859202305290586934257","remark":"","items":[{"id":24856152,"name":"怡宝纯净水555ml","buyPrice":1.00000000,"sellPrice":2.00,"customerPrice":2.00,"quantity":14.000,"discount":100.00000,"customerDiscount":100.00,"totalAmount":28.00,"totalProfit":14.00000000,"isCustomerDiscount":1,"productUid":839630792014576874,"productBarcode":"6901285991219","isWeighing":0,"ticketitemattributes":[],"discountDetails":[],"saleGuiderList":[]}],"payments":[{"code":"payCode_-2900","amount":28.00}],"ticketOnTable":{"tableUid":0,"tableAreaUid":0,"tableCardNo":"0022"}},{"cashierUid":832101480292933201,"cashier":{"jobNumber":"1001","name":"刘本之","uid":832101480292933201},"customerUid":0,"uid":1634335269744141504,"sn":"202305291355062500023","datetime":"2023-05-29 13:55:11","totalAmount":12.35,"totalProfit":4.56,"discount":100.00000,"rounding":0.00,"ticketType":"SELL","invalid":0,"sysUpdateTime":"2023-05-29 13:55:12","remark":"","items":[{"id":24856403,"name":"静宁片红苹果90#A级","buyPrice":13.00000000,"sellPrice":24.00,"customerPrice":1.00,"quantity":0.369,"discount":100.00000,"customerDiscount":100.00,"totalAmount":8.85,"totalProfit":4.05625000,"isCustomerDiscount":0,"productUid":629521688225667493,"productBarcode":"2211038","isWeighing":1,"ticketitemattributes":[],"discountDetails":[],"saleGuiderList":[]},{"id":24856404,"name":"伊利纯牛奶250ml","buyPrice":3.00000000,"sellPrice":3.50,"customerPrice":3.50,"quantity":1.000,"discount":100.00000,"customerDiscount":100.00,"totalAmount":3.50,"totalProfit":0.50000000,"isCustomerDiscount":1,"productUid":235408933014276878,"productBarcode":"6907992100272","isWeighing":0,"ticketitemattributes":[],"discountDetails":[],"saleGuiderList":[]}],"payments":[{"code":"payCode_1","amount":12.35}]},{"cashierUid":832101480292933201,"cashier":{"jobNumber":"1001","name":"刘本之","uid":832101480292933201},"customerUid":0,"uid":997131943933226865,"sn":"202305291355337900024","datetime":"2023-05-29 13:55:33","totalAmount":4.00,"totalProfit":1.00,"discount":100.00000,"rounding":0.00,"ticketType":"SELL","invalid":0,"sysUpdateTime":"2023-05-29 13:55:37","externalOrderNo":"4200059246202305293811197983","remark":"","items":[{"id":24856506,"name":"康师傅水蜜桃1L/瓶","buyPrice":3.00000000,"sellPrice":4.00,"customerPrice":4.00,"quantity":1.000,"discount":100.00000,"customerDiscount":100.00,"totalAmount":4.00,"totalProfit":1.00000000,"isCustomerDiscount":1,"productUid":108606589723706730,"productBarcode":"6922456889906","isWeighing":0,"ticketitemattributes":[],"discountDetails":[],"saleGuiderList":[]}],"payments":[{"code":"payCode_-2900","amount":4.00}],"ticketOnTable":{"tableUid":0,"tableAreaUid":0,"tableCardNo":"0024"}},{"cashierUid":832101480292933201,"cashier":{"jobNumber":"1001","name":"刘本之","uid":832101480292933201},"customerUid":0,"uid":168164870064613378,"sn":"202305291444510380025","datetime":"2023-05-29 14:44:51","totalAmount":19.00,"totalProfit":2.00,"discount":100.00000,"rounding":0.00,"ticketType":"SELL","invalid":0,"sysUpdateTime":"2023-05-29 14:44:56","externalOrderNo":"4200001878202305296454372915","remark":"","items":[{"id":24871854,"name":"无码商品","buyPrice":15.00000000,"sellPrice":15.00,"customerPrice":15.00,"quantity":1.000,"discount":100.00000,"customerDiscount":100.00,"totalAmount":15.00,"totalProfit":0E-8,"isCustomerDiscount":0,"productUid":1685342677047973674,"isWeighing":0,"ticketitemattributes":[],"discountDetails":[],"saleGuiderList":[]},{"id":24871855,"name":"农夫山泉天然水550ml/瓶","buyPrice":1.00000000,"sellPrice":2.00,"customerPrice":2.00,"quantity":2.000,"discount":100.00000,"customerDiscount":100.00,"totalAmount":4.00,"totalProfit":2.00000000,"isCustomerDiscount":0,"productUid":126346716668394093,"productBarcode":"6921168509256","isWeighing":0,"ticketitemattributes":[],"discountDetails":[],"saleGuiderList":[]}],"payments":[{"code":"payCode_-2900","amount":19.00}],"ticketOnTable":{"tableUid":0,"tableAreaUid":0,"tableCardNo":"0025"}},{"cashierUid":832101480292933201,"cashier":{"jobNumber":"1001","name":"刘本之","uid":832101480292933201},"customerUid":0,"uid":1379115746226265030,"sn":"202305291535463260026","datetime":"2023-05-29 15:35:46","totalAmount":9.00,"totalProfit":3.00,"discount":100.00000,"rounding":0.00,"ticketType":"SELL","invalid":0,"sysUpdateTime":"2023-05-29 15:35:55","externalOrderNo":"4200066272202305298853790021","remark":"","items":[{"id":24888503,"name":"口水娃元气零食片片香香辣味78g/袋","buyPrice":3.00000000,"sellPrice":4.50,"customerPrice":4.50,"quantity":2.000,"discount":100.00000,"customerDiscount":100.00,"totalAmount":9.00,"totalProfit":3.00000000,"isCustomerDiscount":1,"productUid":951887611489126191,"productBarcode":"6947245887291","isWeighing":0,"ticketitemattributes":[],"discountDetails":[],"saleGuiderList":[]}],"payments":[{"code":"payCode_-2900","amount":9.00}],"ticketOnTable":{"tableUid":0,"tableAreaUid":0,"tableCardNo":"0026"}},{"cashierUid":832101480292933201,"cashier":{"jobNumber":"1001","name":"刘本之","uid":832101480292933201},"customerUid":0,"uid":635955904204826352,"sn":"202305291547394980027","datetime":"2023-05-29 15:47:54","totalAmount":4.00,"totalProfit":1.50,"discount":100.00000,"rounding":0.00,"ticketType":"SELL","invalid":0,"sysUpdateTime":"2023-05-29 15:47:55","remark":"","items":[{"id":24893484,"name":"怡宝纯净水1.555L","buyPrice":2.50000000,"sellPrice":4.00,"customerPrice":4.00,"quantity":1.000,"discount":100.00000,"customerDiscount":100.00,"totalAmount":4.00,"totalProfit":1.50000000,"isCustomerDiscount":1,"productUid":398464377287734739,"productBarcode":"6901285991271","isWeighing":0,"ticketitemattributes":[],"discountDetails":[],"saleGuiderList":[]}],"payments":[{"code":"payCode_1","amount":4.00}]},{"cashierUid":832101480292933201,"cashier":{"jobNumber":"1001","name":"刘本之","uid":832101480292933201},"customerUid":0,"uid":3389519309558740868,"sn":"202305291614514370028","datetime":"2023-05-29 16:14:51","totalAmount":6.00,"totalProfit":1.50,"discount":100.00000,"rounding":0.00,"ticketType":"SELL","invalid":0,"sysUpdateTime":"2023-05-29 16:15:03","externalOrderNo":"4200066272202305293530505599","remark":"","items":[{"id":24905151,"name":"国药集团积醉解风味饮料240ml/罐","buyPrice":4.50000000,"sellPrice":6.00,"customerPrice":6.00,"quantity":1.000,"discount":100.00000,"customerDiscount":100.00,"totalAmount":6.00,"totalProfit":1.50000000,"isCustomerDiscount":1,"productUid":815609676422751865,"productBarcode":"6971772961452","isWeighing":0,"ticketitemattributes":[],"discountDetails":[],"saleGuiderList":[]}],"payments":[{"code":"payCode_-2900","amount":6.00}],"ticketOnTable":{"tableUid":0,"tableAreaUid":0,"tableCardNo":"0028"}},{"cashierUid":832101480292933201,"cashier":{"jobNumber":"1001","name":"刘本之","uid":832101480292933201},"customerUid":0,"uid":1598792652086715612,"sn":"202305291624581700029","datetime":"2023-05-29 16:24:58","totalAmount":30.00,"totalProfit":3.00,"discount":100.00000,"rounding":0.00,"ticketType":"SELL","invalid":0,"sysUpdateTime":"2023-05-29 16:25:03","externalOrderNo":"4200067679202305292865482795","remark":"","items":[{"id":24909874,"name":"无码商品","buyPrice":24.00000000,"sellPrice":24.00,"customerPrice":24.00,"quantity":1.000,"discount":100.00000,"customerDiscount":100.00,"totalAmount":24.00,"totalProfit":0E-8,"isCustomerDiscount":0,"productUid":1685348664415586690,"isWeighing":0,"ticketitemattributes":[],"discountDetails":[],"saleGuiderList":[]},{"id":24909875,"name":"贝卓BAZON尼龙扎带100根(2.5)3*150/袋","buyPrice":3.00000000,"sellPrice":6.00,"customerPrice":6.00,"quantity":1.000,"discount":100.00000,"customerDiscount":100.00,"totalAmount":6.00,"totalProfit":3.00000000,"isCustomerDiscount":1,"productUid":300688425076327003,"productBarcode":"6941334135195","isWeighing":0,"ticketitemattributes":[],"discountDetails":[],"saleGuiderList":[]}],"payments":[{"code":"payCode_-2900","amount":30.00}],"ticketOnTable":{"tableUid":0,"tableAreaUid":0,"tableCardNo":"0029"}},{"cashierUid":832101480292933201,"cashier":{"jobNumber":"1001","name":"刘本之","uid":832101480292933201},"customerUid":0,"uid":308448173958667421,"sn":"202305291626453050030","datetime":"2023-05-29 16:26:47","totalAmount":3.00,"totalProfit":0.80,"discount":100.00000,"rounding":0.00,"ticketType":"SELL","invalid":0,"sysUpdateTime":"2023-05-29 16:26:49","remark":"","items":[{"id":24910750,"name":"可乐可乐经典美味500ML/瓶","buyPrice":2.20000000,"sellPrice":3.00,"customerPrice":3.00,"quantity":1.000,"discount":100.00000,"customerDiscount":100.00,"totalAmount":3.00,"totalProfit":0.80000000,"isCustomerDiscount":0,"productUid":147458061563215496,"productBarcode":"6954767412573","isWeighing":0,"ticketitemattributes":[],"discountDetails":[],"saleGuiderList":[]}],"payments":[{"code":"payCode_1","amount":3.00}]},{"cashierUid":832101480292933201,"cashier":{"jobNumber":"1001","name":"刘本之","uid":832101480292933201},"customerUid":0,"uid":2650702680380045278,"sn":"202305291643189500031","datetime":"2023-05-29 16:43:19","totalAmount":3.50,"totalProfit":0.00,"discount":100.00000,"rounding":0.00,"ticketType":"SELL","invalid":0,"sysUpdateTime":"2023-05-29 16:43:22","externalOrderNo":"4200001858202305293200459411","remark":"","items":[{"id":24919187,"name":"无码商品","buyPrice":3.50000000,"sellPrice":3.50,"customerPrice":3.50,"quantity":1.000,"discount":100.00000,"customerDiscount":100.00,"totalAmount":3.50,"totalProfit":0E-8,"isCustomerDiscount":0,"productUid":1685349794555529180,"isWeighing":0,"ticketitemattributes":[],"discountDetails":[],"saleGuiderList":[]}],"payments":[{"code":"payCode_-2900","amount":3.50}],"ticketOnTable":{"tableUid":0,"tableAreaUid":0,"tableCardNo":"0031"}},{"cashierUid":832101480292933201,"cashier":{"jobNumber":"1001","name":"刘本之","uid":832101480292933201},"customerUid":0,"uid":4484746223952809016,"sn":"202305291654044170032","datetime":"2023-05-29 16:54:04","totalAmount":17.00,"totalProfit":5.00,"discount":100.00000,"rounding":0.00,"ticketType":"SELL","invalid":0,"sysUpdateTime":"2023-05-29 16:54:08","externalOrderNo":"4200067678202305294044848839","remark":"","items":[{"id":24924812,"name":"百草味甄选清甜白桃干果脯45g/袋","buyPrice":5.20000000,"sellPrice":7.00,"customerPrice":7.00,"quantity":1.000,"discount":100.00000,"customerDiscount":100.00,"totalAmount":7.00,"totalProfit":1.80000000,"isCustomerDiscount":1,"productUid":409651947091407190,"productBarcode":"6941410725333","isWeighing":0,"ticketitemattributes":[],"discountDetails":[],"saleGuiderList":[]},{"id":24924813,"name":"零嘴上零食虎皮凤爪鲜辣味70克/袋","buyPrice":6.80000000,"sellPrice":10.00,"customerPrice":10.00,"quantity":1.000,"discount":100.00000,"customerDiscount":100.00,"totalAmount":10.00,"totalProfit":3.20000000,"isCustomerDiscount":1,"productUid":794874512156681613,"productBarcode":"4897115501098","isWeighing":0,"ticketitemattributes":[],"discountDetails":[],"saleGuiderList":[]}],"payments":[{"code":"payCode_-2900","amount":17.00}],"ticketOnTable":{"tableUid":0,"tableAreaUid":0,"tableCardNo":"0032"}},{"cashierUid":832101480292933201,"cashier":{"jobNumber":"1001","name":"刘本之","uid":832101480292933201},"customerUid":0,"uid":296197634688158735,"sn":"202305291656477840033","datetime":"2023-05-29 16:56:47","totalAmount":3.50,"totalProfit":1.00,"discount":100.00000,"rounding":0.00,"ticketType":"SELL","invalid":0,"sysUpdateTime":"2023-05-29 16:56:51","externalOrderNo":"4200001859202305293837948897","remark":"","items":[{"id":24926248,"name":"真果粒草莓味250g(盒)","buyPrice":2.50000000,"sellPrice":3.50,"customerPrice":3.50,"quantity":1.000,"discount":100.00000,"customerDiscount":100.00,"totalAmount":3.50,"totalProfit":1.00000000,"isCustomerDiscount":1,"productUid":407736867120106061,"productBarcode":"6923644268503","isWeighing":0,"ticketitemattributes":[],"discountDetails":[],"saleGuiderList":[]}],"payments":[{"code":"payCode_-2900","amount":3.50}],"ticketOnTable":{"tableUid":0,"tableAreaUid":0,"tableCardNo":"0033"}},{"cashierUid":832101480292933201,"cashier":{"jobNumber":"1001","name":"刘本之","uid":832101480292933201},"customerUid":0,"uid":1562478375889523038,"sn":"202305291659156400034","datetime":"2023-05-29 16:59:15","totalAmount":3.00,"totalProfit":0.50,"discount":100.00000,"rounding":0.00,"ticketType":"SELL","invalid":0,"sysUpdateTime":"2023-05-29 16:59:19","externalOrderNo":"4200001867202305293212171237","remark":"","items":[{"id":24927811,"name":"景田纯净水1.5L","buyPrice":2.50000000,"sellPrice":3.00,"customerPrice":3.50,"quantity":1.000,"discount":100.00000,"customerDiscount":100.00,"totalAmount":3.00,"totalProfit":0.50000000,"isCustomerDiscount":1,"productUid":1681447118029731714,"productBarcode":"6944649700126","isWeighing":0,"ticketitemattributes":[],"discountDetails":[],"saleGuiderList":[]}],"payments":[{"code":"payCode_-2900","amount":3.00}],"ticketOnTable":{"tableUid":0,"tableAreaUid":0,"tableCardNo":"0034"}},{"cashierUid":832101480292933201,"cashier":{"jobNumber":"1001","name":"刘本之","uid":832101480292933201},"customerUid":0,"uid":90728990137448333,"sn":"202305291713143400035","datetime":"2023-05-29 17:13:14","totalAmount":3.00,"totalProfit":1.00,"discount":100.00000,"rounding":0.00,"ticketType":"SELL","invalid":0,"sysUpdateTime":"2023-05-29 17:13:18","externalOrderNo":"4200001878202305294321556096","remark":"","items":[{"id":24936168,"name":"宜简白桃味苏打水饮品360ml/瓶","buyPrice":2.00000000,"sellPrice":3.00,"customerPrice":3.00,"quantity":1.000,"discount":100.00000,"customerDiscount":100.00,"totalAmount":3.00,"totalProfit":1.00000000,"isCustomerDiscount":1,"productUid":867168497559034854,"productBarcode":"6950549800354","isWeighing":0,"ticketitemattributes":[],"discountDetails":[],"saleGuiderList":[]}],"payments":[{"code":"payCode_-2900","amount":3.00}],"ticketOnTable":{"tableUid":0,"tableAreaUid":0,"tableCardNo":"0035"}}],"pageSize":100}}', true);
- if ($orders['status'] == 'success') {
- $data = $orders['data']['result'];
- foreach ($data as $order) {
- if($order['ticketType'] == 'SELL_RETURN'){
- continue;
- }
- $syncOrder = $this->syncOrder($order);
- if($syncOrder['code'] == 0){
- $okCount++;
- }else{
- \Yii::error([__METHOD__, $param, $okCount, $syncOrder]);
- // return $syncOrder;
- }
- }
- if(count($data) == $orders['data']['pageSize']){
- empty($orders['data']['postBackParameter']) || $param['postBackParameter'] = $orders['data']['postBackParameter'];
- return $this->syncOrders($param, $okCount);
- }
- $uids = [];
- foreach($this->needSyncStockUids() as $item){
- $productUid = $item['productUid'];
- $syncGoodsStock = $this->syncGoodsStock($productUid);
- $orderIdMax = $item['orderid'];
- $this->setSyncCache(OptionSetting::POSPAL_SYNC_STOCK_ORDERID_MAX, $orderIdMax);
- if($syncGoodsStock['code'] != 0){
- \Yii::error([__METHOD__, $param, $productUid, $syncGoodsStock]);
- return [
- 'code' => 1,
- 'msg' => '同步失败,syncGoodsStock错误' . $syncGoodsStock['msg'],
- ];
- }
- $uids[$productUid] = 1;
- }
- foreach($this->needSyncStockUidsYb() as $item){
- $productUid = $item['productUid'];
- if(isset($uids[$productUid])){
- continue;
- }
- $syncGoodsStock = $this->syncGoodsStock($productUid);
- $orderIdMax = $item['orderid'];
- $this->setSyncCache(OptionSetting::POSPAL_SYNC_STOCK_YB_ORDERID_MAX, $orderIdMax);
- if($syncGoodsStock['code'] != 0){
- \Yii::error([__METHOD__, $param, $productUid, $syncGoodsStock]);
- return [
- 'code' => 1,
- 'msg' => '同步失败,syncGoodsStock错误' . $syncGoodsStock['msg'],
- ];
- }
- }
- return [
- 'code' => 0,
- 'msg' => '同步成功,数量:' . $okCount,
- ];
- }
- \Yii::error([__METHOD__, $param, $orders]);
- return [
- 'code' => 1,
- 'msg' => '银豹订单数据获取失败,同步数量:' . $okCount,
- ];
- }
- public function syncOrder($order){
- \Yii::error([__METHOD__, 'syncOrder', $order['sn']]);
- if($this->hasOrder($order['sn'])){
- return [
- 'code' => 0,
- 'msg' => '此前已同步成功',
- ];
- }
- $t = \Yii::$app->db->beginTransaction();
- try{
- $customerUid = $order['customerUid'];
- if($customerUid){
- $syncUser = $this->syncUser($customerUid);
- if($syncUser['code'] != 0){
- $t->rollBack();
- return [
- 'code' => 1,
- 'msg' => '同步失败,syncUser错误' . $syncUser['msg'],
- ];
- }
- }
- $syncUids = [];
- $items = $order['items'];
- foreach ($items as $item) {
- $productUid = $item['productUid'];
- if(!$this->hasGoods($productUid)){
- $syncUids[] = $productUid;
- }
- $this->sync_stock_uids[$productUid] = $productUid;
- $syncGoods = $this->syncGoods($productUid);
- if($syncGoods['code'] != 0){
- $t->rollBack();
- return [
- 'code' => 1,
- 'msg' => '同步失败,syncGoods错误' . $syncGoods['msg'],
- ];
- }
- }
- $add = $this->addOrder($order, $syncUids);
- if(!$add){
- $t->rollBack();
- return [
- 'code' => 1,
- 'msg' => '同步失败,addOrder错误',
- ];
- }
- $savePospalOrder = $this->savePospalOrder(0, $order, $add->id);
- if(!$savePospalOrder){
- $t->rollBack();
- return [
- 'code' => 1,
- 'msg' => '同步失败,savePospalOrder错误',
- ];
- }
- $t->commit();
- \Yii::error([__METHOD__, '$savePospalOrder', $savePospalOrder, $order['sn']]);
- } catch (\Exception $e) {
- $t->rollBack();
- \Yii::error([__METHOD__, $e]);
- return [
- 'code' => 1,
- 'msg' => '同步失败,' . $e->getMessage(),
- ];
- }
- return [
- 'code' => 0,
- 'msg' => '同步成功',
- ];
- }
- public function syncUser($uid, $phone = ''){
- if($phone){
- if($this->hasUserPhone($phone)){
- return [
- 'code' => 0,
- 'msg' => '此前已同步成功',
- ];
- }
- }else{
- if(empty($uid)){
- return [
- 'code' => 0,
- 'msg' => 'uid为空',
- ];
- }
- if($this->hasUser($uid)){
- return [
- 'code' => 0,
- 'msg' => '此前已同步成功',
- ];
- }
- }
- $t = \Yii::$app->db->beginTransaction();
- try{
- if($phone){
- $api = Api::queryUserBytel($this->store_id, $phone);
- }else{
- $api = Api::queryUserByUid($this->store_id, $uid);
- }
- if ($api['status'] != 'success') {
- \Yii::error([__METHOD__, $uid, $phone, $api]);
- $t->rollBack();
- return [
- 'code' => 1,
- 'msg' => '同步失败,queryUserByUid错误' . json_encode($api['messages']),
- ];
- }
- $user = $api['data'];
- $add = $this->addUser($user);
- if(!$add){
- \Yii::error([__METHOD__, $uid, $user, $add]);
- $t->rollBack();
- return [
- 'code' => 1,
- 'msg' => '同步失败,addUser错误',
- ];
- }
- $savePospalUser = $this->savePospalUser($uid, $user, $add->id);
- if(!$savePospalUser){
- \Yii::error([__METHOD__, $uid, $user, $add, $savePospalUser]);
- $t->rollBack();
- return [
- 'code' => 1,
- 'msg' => '同步失败,savePospalUser错误',
- ];
- }
- $t->commit();
- return [
- 'code' => 0,
- 'msg' => '同步成功',
- ];
- } catch (\Exception $e) {
- $t->rollBack();
- \Yii::error([__METHOD__, $e]);
- return [
- 'code' => 1,
- 'msg' => '同步失败,' . $e->getMessage(),
- ];
- }
- }
- public function syncCat($param = [], $okCount = 0){
- $t = \Yii::$app->db->beginTransaction();
- try{
- $cats = Api::queryProductCategoryPages($this->store_id, $param);
- if ($cats['status'] == 'success') {
- $data = $cats['data']['result'];
- $catname = [];
- foreach ($data as $item) {
- if(isset($catname[$item['name']])){
- \Yii::error([__METHOD__, $param, $item, $catname[$item['name']]]);
- $t->rollBack();
- return [
- 'code' => 1,
- 'msg' => '同步失败,银豹系统分类名称有重复' . $item['name'],
- ];
- }
- $catname[$item['name']] = $item['name'];
- $okCount++;
- $pcat = $this->hasCat($item['uid']);
- if($pcat){
- continue;
- }
- $cats = Cat::findAll(['store_id' => $this->store_id, 'name' => $item['name']]);
- $cid = 0;
- foreach ($cats as $cat) {
- if(!$pcat = PospalCat::findOne(['store_id' => $this->store_id, 'cat_id' => $cat->id])){
- $cid = $cat->id;
- }
- }
- if(!$cid){
- $catModel = new Cat();
- $catModel->store_id = $this->store_id;
- $catModel->name = $item['name'];
- $add = $catModel->save();
- $cid = $add->id;
- }
- $savePospalCat = $this->savePospalCat($item['uid'], $item, $cid);
- if(!$savePospalCat){
- \Yii::error([__METHOD__, $param, $okCount, $savePospalCat]);
- $t->rollBack();
- return [
- 'code' => 1,
- 'msg' => '同步失败,savePospalCat错误',
- ];
- }
- }
- if(count($data) < $cats['data']['pageSize']){
- empty($cats['data']['postBackParameter']) || $param['postBackParameter'] = $cats['data']['postBackParameter'];
- $t->commit();
- return $this->syncCat($param, $okCount);
- }
- $allPospalCat = PospalCat::findAll(['store_id' => $this->store_id]);
- foreach ($allPospalCat as $item) {
- if($item->parentUid){
- $pcat = $this->hasCat($item->parentUid);
- $cat = Cat::findOne($item->cat_id);
- $cat->parent_id = $pcat->cat_id;
- $save = $cat->save();
- if(!$save){
- \Yii::error([__METHOD__, $param, $item, $cat]);
- $t->rollBack();
- return [
- 'code' => 1,
- 'msg' => '同步失败,$cat->save()错误',
- ];
- }
- }
- }
- $t->commit();
- return [
- 'code' => 0,
- 'msg' => '同步成功,数量:' . $okCount,
- ];
- }
- \Yii::error([__METHOD__, $param, $cats]);
- $t->rollBack();
- return [
- 'code' => 1,
- 'msg' => '银豹分类数据获取失败,同步数量:' . $okCount,
- ];
- } catch (\Exception $e) {
- $t->rollBack();
- \Yii::error([__METHOD__, $e]);
- return [
- 'code' => 1,
- 'msg' => '同步失败,' . $e->getMessage(),
- ];
- }
- }
- public function syncGoodsStock($uid, $baseOn = 0){
- if(!$pgoods = $this->hasGoods($uid)){
- $syncGoods = $this->syncGoods($uid);
- if($syncGoods['code'] != 0){
- \Yii::error([__METHOD__, $uid, $syncGoods]);
- return [
- 'code' => 1,
- 'msg' => '同步失败' . $syncGoods['msg'],
- ];
- }
- $pgoods = $this->hasGoods($uid);
- }
- $pProduct = Api::queryProductByUid($this->store_id, $uid);
- if ($pProduct['status'] != 'success') {
- \Yii::error([__METHOD__, $uid, $pProduct]);
- return [
- 'code' => 1,
- 'msg' => '同步失败,queryProductByUid接口调用失败',
- ];
- }
- if (!$pProduct['data']) {
- \Yii::error([__METHOD__, $uid, $pProduct]);
- return [
- 'code' => 1,
- 'msg' => '同步失败,没有找到银豹商品',
- ];
- }
- $pstock = $pProduct['data']['stock'];
- $goods = Goods::findOne($pgoods['goods_id']);
- $gattrid = $this->getGoodsAttrIdByPuid($uid);
- if(!$gattrid){
- \Yii::error([__METHOD__, $uid, $goods, $gattrid]);
- return [
- 'code' => 1,
- 'msg' => '同步失败,没有找到规格' . $uid,
- ];
- }
- $attr = json_decode($goods->attr, true);
- $attr_id_list = [];
- $gstock = intval($attr[$gattrid - 1]['num']);
- foreach ($attr[$gattrid - 1]['attr_list'] as $item) {
- array_push($attr_id_list, $item['attr_id']);
- }
- if($gstock != $pstock){
- if($baseOn == 0){
- $api = Api::updateProductInfo($this->store_id, [
- 'productInfo' => [
- 'uid' => $uid,
- 'stock' => $gstock,
- ]
- ]);
- if ($api['status'] != 'success') {
- \Yii::error([__METHOD__, $uid, $gstock, $api]);
- return [
- 'code' => 1,
- 'msg' => '同步失败,接口调用失败updateProductInfo',
- ];
- }
- }
- if($baseOn == 1){
- $add = $goods->numAdd($attr_id_list, $pstock - $gstock);
- if (!$add) {
- \Yii::error([__METHOD__, $uid, $attr_id_list, $pstock, $gstock, $goods]);
- return [
- 'code' => 1,
- 'msg' => '同步失败,numAdd错误',
- ];
- }
- }
- }
- return [
- 'code' => 0,
- 'msg' => '同步成功',
- ];
- }
- public function syncGoodsStockByGoodsId($id, $baseOn = 0) {
- $pgoods = PospalGoods::findAll(['store_id' => $this->store_id, 'goods_id' => $id]);
- if(!$pgoods){
- $syncGoods2Yinbao = $this->syncGoods2Yinbao($id);
- if($syncGoods2Yinbao['code'] != 0){
- \Yii::error([__METHOD__, $id, $syncGoods2Yinbao]);
- return [
- 'code' => 1,
- 'msg' => '同步失败,syncGoods2Yinbao错误',
- ];
- }
- }
- $pgoods = PospalGoods::findAll(['store_id' => $this->store_id, 'goods_id' => $id]);
- foreach ($pgoods as $item) {
- $syncGoodsStock = $this->syncGoodsStock($item->productUid, $baseOn);
- if($syncGoodsStock['code'] != 0){
- \Yii::error([__METHOD__, $id, $item]);
- return [
- 'code' => 1,
- 'msg' => '同步失败,syncGoodsStock错误',
- ];
- }
- }
- return [
- 'code' => 0,
- 'msg' => '同步成功',
- ];
- }
- public function syncGoods($uid, $barcode = 0){
- if($barcode){
- if($this->hasGoodsBarcode($barcode)){
- return [
- 'code' => 0,
- 'msg' => '此前已同步成功',
- ];
- }
- }else{
- if($this->hasGoods($uid)){
- return [
- 'code' => 0,
- 'msg' => '此前已同步成功',
- ];
- }
- }
- $t = \Yii::$app->db->beginTransaction();
- try{
- if($barcode){
- $api = Api::queryProductByBarcode($this->store_id, $barcode);
- }else{
- $api = Api::queryProductByUid($this->store_id, $uid);
- }
- if ($api['status'] != 'success') {
- \Yii::error([__METHOD__, $uid, $barcode, $api]);
- $t->rollBack();
- return [
- 'code' => 1,
- 'msg' => '同步失败,queryProductByUid错误' . json_encode($api['messages']),
- ];
- }
- if(empty($api['data'])){
- $t->rollBack();
- return [
- 'code' => 0,
- 'msg' => '未知商品',
- ];
- }
- $goods = $api['data'];
- $add = $this->addGoods($goods);
- if(!$add){
- \Yii::error([__METHOD__, $uid, $barcode, $goods]);
- $t->rollBack();
- return [
- 'code' => 1,
- 'msg' => '同步失败,addGoods错误',
- ];
- }
- $savePospalGoods = $this->savePospalGoods($uid, $goods, $add->id);
- if(!$savePospalGoods){
- \Yii::error([__METHOD__, $uid, $barcode, $goods, $savePospalGoods]);
- $t->rollBack();
- return [
- 'code' => 1,
- 'msg' => '同步失败,savePospalGoods错误',
- ];
- }
- $t->commit();
- return [
- 'code' => 0,
- 'msg' => '同步成功',
- ];
- } catch (\Exception $e) {
- $t->rollBack();
- \Yii::error([__METHOD__, $e]);
- return [
- 'code' => 1,
- 'msg' => '同步失败,' . $e->getMessage(),
- ];
- }
- }
- public function hasOrder($sn){
- $res = PospalOrder::findOne(['store_id' => $this->store_id, 'sn' => $sn]);
- return $res;
- }
- public function hasUser($uid){
- $res = PospalUser::findOne(['store_id' => $this->store_id, 'customerUid' => $uid]);
- return $res;
- }
- public function hasUserPhone($phone){
- $res = PospalUser::findOne(['store_id' => $this->store_id, 'phone' => $phone]);
- return $res;
- }
- public function hasCat($uid){
- $res = PospalCat::findOne(['store_id' => $this->store_id, 'uid' => $uid]);
- if(!$res){
- $syncCat = $this->syncCat();
- if($syncCat){
- $res = PospalCat::findOne(['store_id' => $this->store_id, 'uid' => $uid]);
- return $res;
- }
- }
- return $res;
- }
- public function hasGoods($uid){
- $res = PospalGoods::findOne(['store_id' => $this->store_id, 'productUid' => $uid]);
- return $res;
- }
- public function hasGoodsBarcode($barcode){
- $res = PospalGoods::findOne(['store_id' => $this->store_id, 'barcode' => $barcode]);
- return $res;
- }
- public function savePospalOrder($uid, $data, $id){
- $model = new PospalOrder();
- $model->store_id = $this->store_id;
- empty($data['uid']) || $model->uid = $data['uid'];
- $model->sn = $data['sn'];
- empty($data['webOrderNo']) || $model->webOrderNo = $data['webOrderNo'];
- $model->json = json_encode($data);
- $model->order_id = $id;
- $res = $model->save();
- if(!$res){
- \Yii::error([__METHOD__, $data, $model]);
- }
- return $res;
- }
- public function savePospalUser($uid, $data, $id){
- $model = new PospalUser();
- $model->store_id = $this->store_id;
- $model->customerUid = $data['customerUid'];
- $model->number = $data['number'];
- $model->phone = $data['phone'];
- $model->json = json_encode($data);
- $model->user_id = $id;
- $res = $model->save();
- if(!$res){
- \Yii::error([__METHOD__, $data, $model]);
- }
- return $res;
- }
- public function savePospalCat($uid, $data, $id){
- $model = new PospalCat();
- $model->store_id = $this->store_id;
- $model->uid = $data['uid'];
- $model->parentUid = $data['parentUid'];
- $model->name = $data['name'];
- $model->cat_id = $id;
- $res = $model->save();
- if(!$res){
- \Yii::error([__METHOD__, $data, $model]);
- }
- return $res;
- }
- public function savePospalGoods($uid, $data, $id){
- $model = new PospalGoods();
- $model->store_id = $this->store_id;
- $model->productUid = $data['uid'];
- $model->barcode = $data['barcode'];
- $model->spu = $data['attribute5'];
- $model->json = json_encode($data);
- $model->goods_id = $id;
- $res = $model->save();
- if(!$res){
- \Yii::error([__METHOD__, $data, $model]);
- }
- return $res;
- }
- public function addOrder($data, $syncUids = []){
- $userid = 0;
- if($data['customerUid']){
- $puser = $this->hasUser($data['customerUid']);
- if(!$puser){
- \Yii::error([__METHOD__, $data, $puser]);
- return false;
- }
- $userid = $puser['user_id'];
- }
- $totalAmount = $data['totalAmount'];
- $integral = ['forehead' => 0, 'forehead_integral' => 0];
- if($data['pointUsage']){
- $integral = ['forehead' => $data['pointUsage']['money'], 'forehead_integral' => $data['pointUsage']['point']];
- }
- $pay_type = 6;
- if($data['payments']){
- foreach($data['payments'] as $pay){
- //储值卡
- if($pay['code'] == 'payCode_2'){
- $pay_type = 3;
- break;
- }
- }
- }
- $model = new OrderPospal();
- $model->store_id = $this->store_id;
- $model->user_id = $userid;
- $model->order_no = 'YB'.$data['sn'];
- $model->total_price = $totalAmount;
- $model->pay_price = $totalAmount;
- $model->integral_price = 0;
- $model->integral = json_encode($integral);
- $model->created_at = time();
- $model->is_offline = 1;
- $model->version = cyy_version();
- $model->discount = $data['discount'] / 10;
- $model->remark = $data['remark'];
- $model->pay_type = $pay_type;
- $model->trade_status = Order::ORDER_FLOW_CONFIRM;
- $model->is_pay = 1;
- $model->pay_time = strtotime($data['datetime']);
- $model->confirm_time = strtotime($data['datetime']);
- $model->send_time = strtotime($data['datetime']);
- $model->created_at = strtotime($data['datetime']);
- $model->first_price = 0;
- $model->second_price = 0;
- $model->third_price = 0;
- $res = $model->save();
- if(!$res){
- \Yii::error([__METHOD__, $data, $model]);
- return false;
- }
- //orderdetail减库存
- $goods_profit = 0;
- foreach($data['items'] as $item){
- $uid = $item['productUid'];
- $pGoods = $this->hasGoods($uid);
- if(!$pGoods){
- continue;
- }
- $goods = Goods::findOne($pGoods->goods_id);
- $gattrid = $this->getGoodsAttrIdByPuid($uid);
- if(!$gattrid){
- continue;
- }
- $attr_id_list = [];
- $attrs = [];
- $attr = json_decode($goods->attr, true);
- foreach ($attr[$gattrid - 1]['attr_list'] as $attritem) {
- $attrs[] = $attritem['attr_name'];
- array_push($attr_id_list, $attritem['attr_id']);
- }
- $attr_list = Attr::find()->alias('a')
- ->select('ag.id AS attr_group_id,ag.attr_group_name,a.id AS attr_id,a.attr_name')
- ->leftJoin(['ag' => AttrGroup::tableName()], 'a.attr_group_id=ag.id')
- ->where(['a.id' => $attr_id_list, 'ag.store_id' => $this->store_id,])
- ->asArray()->all();
- $order_detail = new OrderPospalDetail();
- $order_detail->order_id = $model->id;
- $order_detail->goods_id = $pGoods->goods_id;
- $order_detail->num = $item['quantity'] <= 0 ? 0 : intval($item['quantity']);
- $order_detail->total_price = $item['totalAmount'];
- $order_detail->goods_name = $goods->name . ' ' . implode('/', $attrs);
- $order_detail->goods_info = $goods ? json_encode($goods->toArray()) : json_encode([]);
- $order_detail->pic = $goods->cover_pic;
- $order_detail->attr = json_encode($attr_list, JSON_UNESCAPED_UNICODE);
- $order_detail->delivery_type = OrderDetail::GOODS_DELIVERY_SHOP;
- // 计算单个商品可分红金额
- $profit = $goods->rate_type == 0 ? floatval($order_detail->total_price * $goods->rate / 100) : $goods->rate;
- $goods_profit += $profit;
- $order_detail->profit = $profit;
- $odSave = $order_detail->save();
- if($odSave){
- if(!in_array($uid, $syncUids)){
- $numSub = $goods->numSub($attr_id_list, $item['quantity']);
- if(!$numSub){
- \Yii::error([__METHOD__, $numSub, $item, $order_detail]);
- }
- }
- }else{
- \Yii::error([__METHOD__, $item, $order_detail]);
- }
- }
- // goods_profit 计算之后存入订单表中
- $model->profit = $goods_profit;
- $model->save();
- if(!$userid){
- return $model;
- }
- //减余额积分
- if($data['payments']){
- foreach($data['payments'] as $pay){
- //储值卡
- if($pay['code'] == 'payCode_2'){
- $amount = $pay['amount'];
- AccountLog::saveLog($userid, $amount, AccountLog::TYPE_BALANCE, AccountLog::LOG_TYPE_EXPEND, 0, $model->id, '银豹消费,订单号:'.$data['sn']);
- }
- }
- }
- if($data['pointUsage']){
- if($data['pointUsage']['point'] > 0){
- $amount = $data['pointUsage']['point'];
- AccountLog::saveLog($userid, $amount, AccountLog::TYPE_INTEGRAL, AccountLog::LOG_TYPE_EXPEND, 0, $model->id, '银豹消费,订单号:'.$data['sn']);
- }
- }
-
- // 绑定上下级
- $user = User::findOne($userid);
- if ($user && $user->parent_user_id) {
- $this->saveParentId($user);
- $this->saveParentId($user, 2);
- }
-
- $this->setReturnData($model);
-
-
- // $form = new OrderComplete();
- // $form->order_id = $order->id;
- // $form->order_type = 0;
- // $form->store_id = get_store_id();
- // $form->notify();
-
- // 消费满指定金额自动成为分销商
- $this->autoBecomeShare($userid, $this->store_id, 'STORE');
- // 购买指定或任意商品自动成为分销商
- $this->autoBuyGood($userid, $this->store_id, $model->id);
-
-
- $model->is_sale = 1;
- $model->save();
- $this->share_money($model);
-
- return $model;
- }
- /**
- * 分销订单佣金结算
- * @param Order $order
- */
- private function sendOrderProfit($order, $expire_day = 0) {
- if (!$order->share_order_profit) {
- \Yii::warning('订单佣金可分发值为0');
- return;
- }
- $user_share = UserShareLog::find()->where(['user_id' => $order->user_id])->orderBy('created_at desc')->limit(1)->asArray()->one();
- \Yii::warning($user_share);
- if (empty($user_share)) {
- \Yii::warning('订单佣金未找到分享关系');
- return;
- }
- if ($expire_day > 0) {
- if ($order->pay_time - $user_share['created_at'] > $expire_day * 24 * 3600) {
- \Yii::warning('订单佣金分享关系已过期');
- return;
- }
- }
- $user = User::findOne($user_share['parent_id']);
- if (!$user) {
- \Yii::warning('订单佣金未找到分享关系用户');
- return;
- }
- if ($order->share_send_type == 2) {
- AccountLog::saveLog($user_share['parent_id'], $order->share_order_profit, AccountLog::TYPE_INTEGRAL,
- AccountLog::LOG_TYPE_INCOME, AccountLog::TYPE_PLATFORM_ORDER,
- $order->id, "商城订单佣金赠送积分, 订单号:{$order->order_no}");
- } else if ($order->share_send_type == 3) {
- AccountLog::saveLog($user_share['parent_id'], $order->share_order_profit, AccountLog::TYPE_BALANCE,
- AccountLog::LOG_TYPE_INCOME, AccountLog::TYPE_PLATFORM_ORDER,
- $order->id, "商城订单佣金赠送余额, 订单号:{$order->order_no}");
- } else {
- $user->total_price += doubleval($order->share_order_profit);
- $user->price += doubleval($order->share_order_profit);
- $user->save();
- $order->share_price += doubleval($order->share_order_profit);
- $order->save();
- UserShareMoney::set($order->share_order_profit, $user->id, $order->id, 0, 5, $order->store_id, 0);
- }
- }
- // 分销订单佣金结算
- private function share_money($order)
- {
- if (!$order) {
- return;
- }
- if ($order->is_price != 0) {
- return;
- }
- //排除商盟订单
- if($order->user_id == 0) {
- return;
- }
- $setting = Option::get('share_money_setting', $this->store_id);
- $setting = $setting ? json_decode($setting['value'], true) : [];
- if (!$setting) {
- \Yii::warning('订单佣金发送:未开启分销设置1');
- return;
- }
- // if (!is_array($setting['commission_type']) || empty($setting['commission_type'])) {
- // \Yii::warning('订单佣金发送:未开启分销设置2');
- // return;
- // }
- // $commission_type = $setting['commission_type'];
- // // 订单佣金 2
- // if (in_array(2, $commission_type)) {
- $this->sendOrderProfit($order, $setting['expire_day']);
- // } else {
- // \Yii::warning('订单佣金发送:未开启订单佣金分销');
- // }
- // // 会员佣金
- // if (!in_array(1, $commission_type)) {
- // \Yii::warning('订单佣金发送:未开启会员佣金分销');
- // return;
- // }
- $share_setting = Option::get('share_basic_setting', $this->store_id);
- $share_setting = $share_setting ? json_decode($share_setting['value'], true) : [];
- // 分销商自购返利
- $order->share_price = 0;
- $user = User::findOne(['id' => $order->user_id]);
- if ($order->rebate > 0) {
- if ($order->share_send_type == 2) {
- AccountLog::saveLog($order->user_id, $order->rebate, AccountLog::TYPE_INTEGRAL,
- AccountLog::LOG_TYPE_INCOME, AccountLog::TYPE_PLATFORM_ORDER,
- $order->id, "商城订单自购返利赠送积分, 订单号:{$order->order_no}");
- } else if ($order->share_send_type == 3) {
- AccountLog::saveLog($order->user_id, $order->rebate, AccountLog::TYPE_BALANCE,
- AccountLog::LOG_TYPE_INCOME, AccountLog::TYPE_PLATFORM_ORDER,
- $order->id, "商城订单自购返利赠送余额, 订单号:{$order->order_no}");
- } else {
- $user->total_price += doubleval($order->rebate);
- $user->price += doubleval($order->rebate);
- $user->save();
- $order->share_price += doubleval($order->rebate);
- UserShareMoney::set($order->rebate, $user->id, $order->id, 0, 4, $order->store_id, 0);
- }
- $order->is_price = 1;
- }
- // 一级佣金发放
- if ($share_setting['level']['value'] >= 1) {
- $user_1 = User::findOne($order->parent_id);
- if (!$user_1) {
- $order->save();
- return;
- }
- if ($order->share_send_type == 2) {
- AccountLog::saveLog($user_1->id, $order->first_price, AccountLog::TYPE_INTEGRAL,
- AccountLog::LOG_TYPE_INCOME, AccountLog::TYPE_PLATFORM_ORDER,
- $order->id, "商城订单分销赠送积分, 订单号:{$order->order_no}");
- } else if ($order->share_send_type == 3) {
- AccountLog::saveLog($user_1->id, $order->first_price, AccountLog::TYPE_BALANCE,
- AccountLog::LOG_TYPE_INCOME, AccountLog::TYPE_PLATFORM_ORDER,
- $order->id, "商城订单分销赠送余额, 订单号:{$order->order_no}");
- } else {
- $user_1->total_price += $order->first_price;
- $user_1->price += $order->first_price;
- $user_1->save();
- UserShareMoney::set($order->first_price, $user_1->id, $order->id, 0, 1, $order->store_id, 0);
- $order->share_price += doubleval($order->first_price);
- }
- $order->is_price = 1;
- }
- // 二级佣金发放
- if ($share_setting['level']['value'] >= 2) {
- $user_2 = User::findOne($order->parent_id_1);
- if ($user_2) {
- // if (!$user_2) {
- // if ($user_1->parent_id != 0 && $order->parent_id_1 == 0) {
- // $res = $this->money($user_1->parent_id, $order->second_price);
- // UserShareMoney::set($order->second_price, $user_1->parent_id, $order->id, 0, 2, $this->store_id, 0);
- //
- // if ($res['parent_id'] != 0 && $share_setting['level']['value'] == 3) {
- // $res = $this->money($res['parent_id'], $order->third_price);
- // UserShareMoney::set($order->third_price, $res['parent_id'], $order->id, 0, 3, $this->store_id, 0);
- // }
- // }
- // $order->save();
- // return;
- // }
- if ($order->share_send_type == 2) {
- AccountLog::saveLog($user_2->id, $order->second_price, AccountLog::TYPE_INTEGRAL,
- AccountLog::LOG_TYPE_INCOME, AccountLog::TYPE_PLATFORM_ORDER,
- $order->id, "商城订单分销赠送积分, 订单号:{$order->order_no}");
- } else if ($order->share_send_type == 3) {
- AccountLog::saveLog($user_2->id, $order->second_price, AccountLog::TYPE_BALANCE,
- AccountLog::LOG_TYPE_INCOME, AccountLog::TYPE_PLATFORM_ORDER,
- $order->id, "商城订单分销赠送余额, 订单号:{$order->order_no}");
- } else {
- $user_2->total_price += $order->second_price;
- $user_2->price += $order->second_price;
- $user_2->save();
- UserShareMoney::set($order->second_price, $user_2->id, $order->id, 0, 2, $order->store_id, 0);
- $order->share_price += doubleval($order->second_price);
- }
- }
- }
- // 三级佣金发放
- if ($share_setting['level']['value'] >= 3 && $order->rebate == 0) {
- $user_3 = User::findOne($order->parent_id_2);
- if ($user_3) {
- // if (!$user_3) {
- // if ($user_2->parent_id != 0 && $order->parent_id_2 == 0) {
- // $this->money($user_2->parent_id, $order->third_price);
- // UserShareMoney::set($order->third_price, $user_2->parent_id, $order->id, 0, 3, $this->store_id, 0);
- // }
- // $order->save();
- // return;
- // }
- if ($order->share_send_type == 2) {
- AccountLog::saveLog($user_3->id, $order->third_price, AccountLog::TYPE_INTEGRAL,
- AccountLog::LOG_TYPE_INCOME, AccountLog::TYPE_PLATFORM_ORDER,
- $order->id, "商城订单分销赠送积分, 订单号:{$order->order_no}");
- } else if ($order->share_send_type == 3) {
- AccountLog::saveLog($user_3->id, $order->third_price, AccountLog::TYPE_BALANCE,
- AccountLog::LOG_TYPE_INCOME, AccountLog::TYPE_PLATFORM_ORDER,
- $order->id, "商城订单分销赠送余额, 订单号({$order->order_no})");
- } else {
- $user_3->total_price += $order->third_price;
- $user_3->price += $order->third_price;
- $user_3->save();
- UserShareMoney::set($order->third_price, $user_3->id, $order->id, 0, 3, $order->store_id, 0);
- $order->share_price += doubleval($order->third_price);
- }
- }
- }
- //临时关系佣金发放
- if (!empty($order->limit_id) && !empty($order->limit_price)) {
- \Yii::error("临时绑定关系发放佣金", '临时绑定关系发放佣金');
- //临时绑定关系发放佣金
- $bind_log = UserBindLog::findOne($order->limit_id);
- $user = User::findOne($bind_log->parent_id);
- $user->total_price += $order->limit_price;
- $user->price += $order->limit_price;
- if (!$user->save()) {
- \Yii::error("用户佣金保存失败");
- }
- UserShareMoney::set($order->limit_price, $user->id, $order->id, 0, 2, $order->store_id, 0);
- $order->is_send_limit = 1;
- $order->share_price += doubleval($order->limit_price);
- $res = $order->save();
- if (!$res) {
- \Yii::error("订单保存失败");
- };
- } else {
- \Yii::error("订单中临时关系佣金为空");
- }
- $order->save();
- return;
- }
- /**
- * 消费满指定金额自动成为分销商
- * @param $user_id integer 用户id
- */
- private function autoBecomeShare($user_id, $store_id, $type = null)
- {
- $setting = Option::get('share_basic_setting', $store_id);
- $setting = $setting ? json_decode($setting['value'], true) : [];
- $auto_share_val = floatval($setting['auto_share_val']['value']);
- if ($auto_share_val == 0) {
- return;
- }
- $share = Share::findOne(['user_id' => $user_id, 'is_delete' => 0, 'store_id' => $store_id]);
- if ($share && $share->status == 1) {
- return;
- }
- $consumption_sum = Order::find()->where(['user_id' => $user_id, 'is_delete' => 0, 'is_pay' => 1])->sum('pay_price');
- $consumption_sum += OrderPospal::find()->where(['user_id' => $user_id, 'is_delete' => 0, 'is_pay' => 1])->sum('pay_price');
- $consumption_sum = floatval(($consumption_sum ? $consumption_sum : 0));
- if ($consumption_sum < $auto_share_val) {
- return;
- }
- if (!$share || $share->status == 2) {
- $share = new Share();
- $share->user_id = $user_id;
- $share->mobile = '';
- $share->name = '';
- $share->is_delete = 0;
- $share->store_id = $store_id;
- }
- $share->status = 1;
- $share->created_at = time();
- $share->save();
- $user = User::findOne($user_id);
- $user->time = time();
- $user->is_distributor = 1;
- $user->save();
- }
- /**
- * 购买指定商品成为分销商
- */
- public function autoBuyGood($user_id, $store_id, $order_id, $type = 0)
- {
- $setting = Option::get('share_basic_setting', $store_id);
- $setting = $setting ? json_decode($setting['value'], true) : [];
- //如果开启无需审核才能开始走下面逻辑
- if (intval($setting['share_condition']['value']) !== 2) {
- return;
- }
- // 购买商城成分销商关闭状态不执行
- if ($setting['share_goods_status']['value'] == 0) {
- return;
- }
- $share = Share::findOne(['user_id' => $user_id, 'is_delete' => 0, 'store_id' => $store_id]);
- if ($share && $share->status == 1) {
- return;
- }
- $goodIds = OrderPospalDetail::find()->where(['order_id' => $order_id])->select('goods_id')->all();
- $sign = false;
- // 购买任意商品
- if ($setting['share_goods_status']['value'] == 1) {
- $sign = true;
- }
- // 购买指定商品自动成为分销商
- if ($setting['share_goods_status']['value'] == 2) {
- foreach ($goodIds as $item) {
- $goods_ids = \explode(',', $setting['share_goods_id']['value']);
- if (in_array($item->goods_id, $goods_ids)) {
- $sign = true;
- break;
- }
- }
- }
- if ($sign) {
- if (!$share || $share->status == 2) {
- $share = new Share();
- $share->user_id = $user_id;
- $share->mobile = '';
- $share->name = '';
- $share->is_delete = 0;
- $share->store_id = $store_id;
- }
- $share->status = 1;
- $share->created_at = time();
- $share->save();
- $user = User::findOne($user_id);
- $user->time = time();
- $user->is_distributor = 1;
- $user->save();
- }
- }
- /**
- * 设置佣金
- * @param Order $order
- * @return mixed
- */
- private function setReturnData($order)
- {
- $form = new ShareMoneyForm();
- $form->store_id = $order->store_id;
- $form->yinbao = 1;
- $form->order = $order;
- $form->order_type = 0;
- return $form->setData();
- }
- /**
- * 分销 保存上级的ID(用于先成为上下级,再成为分销商)
- * @param $user
- * @return static
- */
- public function saveParentId($user, $condition = 1)
- {
- $parentId = $user->parent_user_id;
- if (!$parentId) {
- return;
- }
- // 父级用户不存在
- $parentUser = User::findOne($parentId);
- if (!$parentUser) {
- return;
- }
- if ($user) {
- $form = new BindForm();
- $form->store_id = $this->store_id;
- $form->user_id = $user->id;
- $form->parent_id = $parentId;
- $form->old_parent_id = $parentId;
- $form->condition = $condition;
- $form->save();
- // $user->parent_user_id = $parentId;
- // $user->save();
- }
- return $user;
- }
- public function addUser($data, $moneyAdd = 0){
- // 创建平台会员saas_user
- $saas_user = SaasUser::find()->where(['mobile' => $data['phone'], 'is_delete' => SaasUser::DELETE_STATUS_FALSE])->one();
- if (!$saas_user) {
- $saas_user = new SaasUser();
- $saas_user->access_token = '';
- $saas_user->name = $data['name'];
- $saas_user->mobile = $data['phone'];
- $saas_user->bytedance_open_id = '';
- $saas_user->platform_open_id = '';
- $saas_user->avatar = \Yii::$app->request->hostInfo . \Yii::$app->request->baseUrl . '/web/v1/statics/images/yinbao.png';
- $saas_user->store_id = $this->store_id;
- $saas_user->save();
- }
- $user = User::findOne(['store_id' => $this->store_id, 'binding' => $data['phone']]);
- if($user){
- if($moneyAdd){
- if($data['balance']){
- AccountLog::saveLog($user->id, $data['balance'], AccountLog::TYPE_BALANCE, AccountLog::LOG_TYPE_INCOME, 0, 0, '银豹同步数据,会员号:'.$data['number'].'银豹会员唯一标识'.$data['customerUid']);
- }
- if($data['point']){
- AccountLog::saveLog($user->id, $data['point'], AccountLog::TYPE_INTEGRAL, AccountLog::LOG_TYPE_INCOME, 0, 0, '银豹同步数据,会员号:'.$data['number'].'银豹会员唯一标识'.$data['customerUid']);
- }
- }
- return $user;
- }
- $model = new User(['yinbaoSync' => 1]);
- $model->store_id = $this->store_id;
- $model->is_delete = User::USER_NOT_DELETE;
- $model->type = User::USER_TYPE_NORMAL;
- $model->binding = $data['phone'];
- $model->nickname = $data['name'];
- $model->avatar_url = \Yii::$app->request->hostInfo . \Yii::$app->request->baseUrl . '/web/v1/statics/images/yinbao.png';
- $model->username = $data['name'];
- $model->password = '';
- $model->access_token = '0';
- $model->level = 0;
- $model->integral = 0;
- $model->money = 0;
- $model->created_at = strtotime($data['createdDate']);
- $res = $model->save();
- if(!$res){
- debug_log([__METHOD__, $model->getErrors(), $data], __CLASS__ . '.log');
- \Yii::error([__METHOD__, $model->getErrors(), $data, $model]);
- }
- if($data['balance']){
- AccountLog::saveLog($model->id, $data['balance'], AccountLog::TYPE_BALANCE, AccountLog::LOG_TYPE_INCOME, 0, 0, '银豹同步数据,会员号:'.$data['number'].'银豹会员唯一标识'.$data['customerUid']);
- }
- if($data['point']){
- AccountLog::saveLog($model->id, $data['point'], AccountLog::TYPE_INTEGRAL, AccountLog::LOG_TYPE_INCOME, 0, 0, '银豹同步数据,会员号:'.$data['number'].'银豹会员唯一标识'.$data['customerUid']);
- }
- return $res ? $model : 0;
- }
- public function addGoods($data){
- // $pcat = $this->hasCat($data['categoryUid']);
- // if(!$pcat){
- // \Yii::error([__METHOD__, $data, $pcat]);
- // return false;
- // }
- // $catid = [$pcat['cat_id']];
- $catid = 0;
- $use_attr = 0;
- $hasSpu = false;
- if($data['attribute6'] && $data['attribute5']){
- $use_attr = 1;
- //有规格 且 已经同步过其他规格
- $hasSpu = PospalGoods::findOne(['store_id' => $this->store_id, 'spu' => $data['attribute5'], ['not', ['productUid' => $data['productUid']]]]);
- }
- if($hasSpu){
- //setattr
- $goodsId = $hasSpu->goods_id;
- $goods = Goods::findOne($goodsId);
- $model = new GoodsForm(['yinbaoSync' => 1]);
- $model->store_id = $this->store_id;
- $model->use_attr = 1;
- $attr = json_decode($goods->attr, true);
- $attr[] = [
- 'attr_list' => [[
- 'attr_group_name' => '规格',
- 'attr_name' => $data['attribute6'],
- ]],
- 'num' => intval($data['stock']),
- 'price' => $data['sellPrice'],
- 'no' => $data['barcode'],
- ];
- $model->attr = $attr;
- $goods->yinbaoSync = 1;
- $model->setAttr($goods);
- return $goods;
- }else{
- $model = new GoodsForm(['yinbaoSync' => 1]);
- $model->store_id = $this->store_id;
- $model->name = $data['name'];
- $model->price = $data['sellPrice'];
- $model->cost_price = $data['buyPrice'];
- $model->goods_num = $data['stock'] <= 0 ? 0 : intval($data['stock']);
- $model->goods_no = $data['barcode'];
- $model->use_attr = $use_attr;
- $attr = [];
- if($use_attr){
- $attr[] = [
- 'attr_list' => [[
- 'attr_group_name' => '规格',
- 'attr_name' => $data['attribute6'],
- ]],
- 'num' => intval($data['stock']),
- 'price' => $data['sellPrice'],
- 'no' => $data['barcode'],
- ];
- $model->attr = $attr;
- }
- $model->cat_id = $catid;
- $model->service = '';
- $model->content = '';
- $model->product_type = 0;
- $model->form = ['is_form' => 0];
- $model->cover_pic = \Yii::$app->request->hostInfo . \Yii::$app->request->baseUrl . '/web/v1/statics/images/yinbao.png';
- $res = $model->save();
- if($res['code'] != 0){
- \Yii::error([__METHOD__, $res, $data, $model]);
- return false;
- }
- return $res['goods'];
- }
- }
- public function getGoodsAttrIdByPuid($uid) {
- $pGoods = $this->hasGoods($uid);
- $pGoodsJson = json_decode($pGoods->json, true);
- if(!$pGoodsJson['attribute5']){
- return 1;
- }
- $goods = Goods::findOne($pGoods->goods_id);
- $attrs = json_decode($goods->attr, true);
- $attrItems = [];
- foreach ($attrs as $i => $attr) {
- if($pGoods->barcode == $attr['no']){
- return $i+1;
- }
- $attrItem = [];
- foreach($attr['attr_list'] as $att){
- $attrItem[] = $att['attr_name'];
- }
- sort($attrItem);
- $attrItems[] = implode('/', $attrItem);
- }
- $pItemJson = json_decode($pGoods->json, true);
- $pAttr = $pItemJson['attribute6'];
- foreach ($attrItems as $i => $attrItem) {
- if($pAttr == $attrItem){
- return $i+1;
- }
- }
- return false;
- }
- public function syncBalancePointByUserId($userId, $pay, $point){
- $pUser = PospalUser::findOne(['store_id' => $this->store_id, 'user_id' => $userId]);
- if($pUser){
- $tel = $pUser->phone;
- $pUserTel = PospalUser::findAll(['store_id' => $this->store_id, 'phone' => $tel]);
- if(count($pUserTel) > 1){
- $users = [];
- $api = Api::queryUserBytel($this->store_id, $tel);
- if ($api['status'] == 'success' && count((array)$api['data'])) {
- foreach((array)$api['data'] as $_uitem){
- $item = [
- 'customerUid' => $_uitem['customerUid'],
- 'balance' => $pay,
- 'point' => $point,
- ];
- if($pay > 0){
- if($_uitem['balance'] < $pay){
- $item['balance'] = $_uitem['balance'];
- }
- }
- $pay -= $item['balance'];
- if($point > 0){
- if($_uitem['point'] < $point){
- $item['point'] = $_uitem['point'];
- }
- }
- $point -= $item['point'];
- if($item['balance'] > 0 || $item['point'] > 0){
- $users[] = $item;
- }
- }
- }else{
- debug_log([__METHOD__, $this->store_id, $tel, $api], __CLASS__ . '.log');
- \Yii::error([__METHOD__, $this->store_id, $tel, $api]);
- }
- }else{
- $users = [
- [
- 'customerUid' => $pUser->customerUid,
- 'balance' => $pay,
- 'point' => $point,
- ]
- ];
- }
- foreach($users as $userItem){
- //同步过用户更新余额积分
- $syncBalancePoint = $this->syncBalancePoint($userItem['customerUid'], $userItem['balance'], $userItem['point']);
- if ($syncBalancePoint['code'] != 0) {
- debug_log([__METHOD__, $userId, $pay, $point, $userItem, $syncBalancePoint], __CLASS__ . '.log');
- \Yii::error([__METHOD__, $userId, $pay, $point, $userItem, $syncBalancePoint]);
- return [
- 'code' => 1,
- 'msg' => '同步失败,syncBalancePoint错误' . $syncBalancePoint['msg'],
- ];
- }
- }
- }else{
- $syncUser2Yinbao = $this->syncUser2Yinbao($userId);
- if(!$syncUser2Yinbao){
- \Yii::error([__METHOD__, $userId, $syncUser2Yinbao]);
- return [
- 'code' => 1,
- 'msg' => '同步失败,syncUser2Yinbao错误'.$userId . $syncUser2Yinbao['msg'],
- ];
- }
- }
- }
- public function syncBalancePoint($uid, $pay, $point){
- if($pay != 0 || $point != 0){
- $api = Api::updateBalancePointByIncrement($this->store_id, [
- 'customerUid' => $uid,
- 'balanceIncrement' => $pay != 0 ? $pay : null,
- 'pointIncrement' => $point != 0 ? $point : null,
- 'dataChangeTime' => date('Y-m-d H:i:s'),
- ]);
- if ($api['status'] != 'success') {
- \Yii::error([__METHOD__, $uid, $pay, $point, $api]);
- return [
- 'code' => 1,
- 'msg' => '同步失败,Api::updateBalancePointByIncrement错误' . json_encode($api['messages']),
- ];
- }
- }
- return [
- 'code' => 0,
- 'msg' => '同步成功,' . $pay . ',' . $point,
- ];
- }
- public function syncOrder2Yinbao($id) {
- $pOrder = PospalOrder::findOne(['store_id' => $this->store_id, 'order_id' => $id]);
- if($pOrder){
- return [
- 'code' => 0,
- 'msg' => '此前已同步成功',
- ];
- }
- $order = Order::findOne($id);
- if(!$order){
- \Yii::error([__METHOD__, $id]);
- return [
- 'code' => 1,
- 'msg' => '同步失败,Order::findOne错误'.$id,
- ];
- }
- $t = \Yii::$app->db->beginTransaction();
- try{
- $userId = $order->user_id;
- $point = 0;
- if($order->integral){
- $integral = json_decode($order->integral, true);
- $point = -$integral['forehead_integral'];
- }
- //余额支付
- $pay = 0;
- if($order->pay_type == 3){
- $pay = -$order->pay_price;
- }
- $syncBalancePointByUserId = $this->syncBalancePointByUserId($userId, $pay, $point);
- if($syncBalancePointByUserId['code'] != 0){
- $t->rollBack();
- \Yii::error([__METHOD__, $userId, $pay, $point, $syncBalancePointByUserId]);
- return [
- 'code' => 1,
- 'msg' => '同步失败,syncBalancePointByUserId错误'.$id . $syncBalancePointByUserId['msg'],
- ];
- }
- $orderDetail = OrderDetail::findAll(['order_id' => $id]);
- foreach ($orderDetail as $detail) {
- $goodsId = $detail->goods_id;
- $syncGoods2Yinbao = $this->syncGoods2Yinbao($goodsId);
- if(!$syncGoods2Yinbao){
- $t->rollBack();
- \Yii::error([__METHOD__, $goodsId, $syncGoods2Yinbao]);
- return [
- 'code' => 1,
- 'msg' => '同步失败,syncGoods2Yinbao错误'.$userId . $syncGoods2Yinbao['msg'],
- ];
- }
- }
- $t->commit();
- return [
- 'code' => 0,
- 'msg' => '同步成功',
- ];
- } catch (\Exception $e) {
- $t->rollBack();
- \Yii::error([__METHOD__, $e]);
- return [
- 'code' => 1,
- 'msg' => '同步失败,' . $e->getMessage(),
- ];
- }
- }
- public function syncGoods2Yinbao($id, $changedAttributes = []) {
- $pGoods = PospalGoods::findOne(['store_id' => $this->store_id, 'goods_id' => $id]);
- $goods = Goods::findOne($id);
- if($pGoods){
- if(isset($changedAttributes['goods_num']) && ($goods->goods_num != $changedAttributes['goods_num'])){
- $syncGoodsStockByGoodsId = $this->syncGoodsStockByGoodsId($id);
- if($syncGoodsStockByGoodsId['code'] != 0){
- \Yii::error([__METHOD__, $id, $pGoods]);
- return [
- 'code' => 1,
- 'msg' => '同步失败,syncGoodsStockByGoodsId错误',
- ];
- }
- }
- return [
- 'code' => 0,
- 'msg' => '此前已同步成功',
- ];
- }
- $t = \Yii::$app->db->beginTransaction();
- try{
- $goods = Goods::findOne($id);
- if(!$goods){
- \Yii::error([__METHOD__, $id, $goods]);
- $t->rollBack();
- return [
- 'code' => 1,
- 'msg' => '同步失败,Goods::findOne错误'.$id,
- ];
- }
- $pcat_id = null;
- $cat = GoodsCat::findOne(['store_id' => $this->store_id, 'goods_id' => $id, 'is_delete' => 0]);
- $pcat = PospalCat::findOne(['store_id' => $this->store_id, 'cat_id' => $cat->id]);
- if($pcat){
- $pcat_id = $pcat['uid'];
- }
- $attr = json_decode($goods->attr, true);
- foreach ($attr as $attrItem) {
- $attrids = [];
- $attrs = [];
- foreach ($attrItem['attr_list'] as $attr_list) {
- $attrids[] = $attr_list['attr_id'];
- $attrs[] = $attr_list['attr_name'];
- }
- $spu = null;
- if($goods->use_attr){
- $spu = $goods->store_id . 'cyy' . $goods->id;
- }
- $barcode = $goods->store_id . 'cyy' . $goods->id . 'c' . implode('c', $attrids);
- $barcode = $attrItem['no'] ? $attrItem['no'] : $barcode;
- $api = Api::addProductInfo($this->store_id, [
- 'productInfo' => [
- 'categoryUid' => $pcat_id,
- 'name' => $goods->name,
- 'barcode' => $barcode,
- 'attribute5' => $spu,
- 'attribute6' => implode('/', $attrs),
- 'buyPrice' => $goods->cost_price ? $goods->cost_price : $attrItem['price'],
- 'sellPrice' => $attrItem['price'],
- 'stock' => $attrItem['num'],
- 'maxStock' => 99999999,
- 'minStock' => 0,
- 'noStock' => 0,
- ]
- ]);
- if ($api['status'] != 'success') {
- \Yii::error([__METHOD__, $goods, $api]);
- $t->rollBack();
- return [
- 'code' => 1,
- 'msg' => '同步失败,Api::addProductInfo错误' . json_encode($api['messages']),
- ];
- }
- $uid = $api['data']['uid'];
- $api = Api::queryProductByUid($this->store_id, $uid);
- if ($api['status'] != 'success') {
- \Yii::error([__METHOD__, $uid, $api]);
- $t->rollBack();
- return [
- 'code' => 1,
- 'msg' => '同步失败,queryProductByUid错误' . json_encode($api['messages']),
- ];
- }
- $savePospalGoods = $this->savePospalGoods($uid, $api['data'], $id);
- if(!$savePospalGoods){
- \Yii::error([__METHOD__, $uid, $api['data'], $id, $savePospalGoods]);
- $t->rollBack();
- return [
- 'code' => 1,
- 'msg' => '同步失败,savePospalGoods错误',
- ];
- }
- }
- $t->commit();
- return [
- 'code' => 0,
- 'msg' => '同步成功',
- ];
- } catch (\Exception $e) {
- $t->rollBack();
- \Yii::error([__METHOD__, $e]);
- return [
- 'code' => 1,
- 'msg' => '同步失败,' . $e->getMessage(),
- ];
- }
-
- }
- public function syncUser2Yinbao($id) {
- $pUser = PospalUser::findOne(['store_id' => $this->store_id, 'user_id' => $id]);
- if($pUser){
- return [
- 'code' => 0,
- 'msg' => '此前已同步成功',
- ];
- }
- $user = User::findOne($id);
- if(!$user){
- \Yii::error([__METHOD__, $id]);
- return [
- 'code' => 1,
- 'msg' => '同步失败,User::findOne错误'.$id,
- ];
- }
- $api = Api::queryUserBytel($this->store_id, $user->binding);
- if ($api['status'] == 'success' && count((array)$api['data'])) {
- \Yii::error([__METHOD__, $user->binding, $api]);
- return [
- 'code' => 1,
- 'msg' => '同步失败,银豹会员已存在相同的手机号' . $user->binding,
- ];
- }
- $t = \Yii::$app->db->beginTransaction();
- try{
- $discount = null;
- $level = Level::findOne(['level' => $user->level]);
- if($level){
- $discount = $level->discount * 10;
- }
- $api = Api::addUser($this->store_id, [
- 'customerInfo' => [
- 'number' => $user->id . 'cyy' . $user->binding,
- 'discount' => $discount,
- 'name' => $user->nickname,
- 'phone' => $user->binding,
- 'point' => $user->integral,
- 'balance' => $user->money,
- 'point' => $user->integral,
- ],
- 'extInfo' => [
- 'totalPoint' => $user->total_integral,
- 'nickName' => $user->nickname,
- ]
- ]);
- if ($api['status'] != 'success') {
- \Yii::error([__METHOD__, $user, $api]);
- $t->rollBack();
- return [
- 'code' => 1,
- 'msg' => '同步失败,Api::addUser错误' . json_encode($api['messages']),
- ];
- }
- $uid = $api['data']['customerUid'];
- $api = Api::queryUserByUid($this->store_id, $uid);
- if ($api['status'] != 'success') {
- \Yii::error([__METHOD__, $uid, $api]);
- $t->rollBack();
- return [
- 'code' => 1,
- 'msg' => '同步失败,queryProductByUid错误' . json_encode($api['messages']),
- ];
- }
- $savePospalUser = $this->savePospalUser($uid, $api['data'], $id);
- if(!$savePospalUser){
- \Yii::error([__METHOD__, $uid, $api['data'], $id, $savePospalUser]);
- $t->rollBack();
- return [
- 'code' => 1,
- 'msg' => '同步失败,savePospalUser错误',
- ];
- }
- $t->commit();
- return [
- 'code' => 0,
- 'msg' => '同步成功',
- ];
- } catch (\Exception $e) {
- $t->rollBack();
- \Yii::error([__METHOD__, $e]);
- return [
- 'code' => 1,
- 'msg' => '同步失败,' . $e->getMessage(),
- ];
- }
- }
- //id544 导入银豹会员
- public function importUser() {
- if(!self::isopen($this->store_id)){
- return [
- 'code' => 1,
- 'msg' => '没有银豹配置信息',
- ];
- }
- set_time_limit(0);
- $filename = $_FILES['excel']['name'];
- $tmpname = $_FILES['excel']['tmp_name'];
- $path = \Yii::$app->basePath . '/web/temp/';
- if(!is_dir($path)){
- mkdir($path);
- }
- $ext = strtolower(pathinfo($filename, PATHINFO_EXTENSION));
- if (($ext != 'xlsx') && ($ext != 'xls')) {
- \Yii::error([__METHOD__, $filename, $ext]);
- return [
- 'code' => 1,
- 'msg' => '请上传excel文件'
- ];
- }
- $file = time() . $this->store_id . '.' . $ext;
- $uploadfile = $path . $file;
- move_uploaded_file($tmpname, $uploadfile);
- $rows = \Spatie\SimpleExcel\SimpleExcelReader::create($uploadfile)
- ->getRows();
- $arr = [];
- $rows->each(function (array $item) use (&$arr) {
- try{
- if (isset($item['会员号(必填)'])) {
- //首先校验是否重复手机号
- // $is_exit_binding_user = User::findOne(['binding' => $item['电话(必填)'], 'store_id' => $this->store_id, 'is_delete' => 0]);
- // if(!$is_exit_binding_user){
- $res = $this->addUser([
- 'number' => $item['会员号(必填)'],
- 'phone' => $item['电话(必填)'],
- 'name' => $item['姓名(必填)'],
- 'level' => 0,
- 'point' => $item['积分(必填)'],
- 'balance' => $item['余额(必填)'],
- ], 1);
- if($res){
- $arr[] = $res;
- }
- // }
- }
- } catch (\Exception $e){
- \Yii::error([__METHOD__, $item, $e]);
- debug_log($e->getMessage());
- }
- });
-
- $count = count($arr);
- @unlink($uploadfile);
- return [
- 'code' => $count ? 0 : 1,
- 'msg' => "共导入{$count}条数据"
- ];
- }
- //id544 导入银豹商品
- public function importProduct() {
- if(!self::isopen($this->store_id)){
- return [
- 'code' => 1,
- 'msg' => '没有银豹配置信息',
- ];
- }
- set_time_limit(0);
- $filename = $_FILES['excel']['name'];
- $tmpname = $_FILES['excel']['tmp_name'];
- $path = \Yii::$app->basePath . '/web/temp/';
- if(!is_dir($path)){
- mkdir($path);
- }
- $ext = strtolower(pathinfo($filename, PATHINFO_EXTENSION));
- if (($ext != 'xlsx') && ($ext != 'xls')) {
- \Yii::error([__METHOD__, $filename, $ext]);
- return [
- 'code' => 1,
- 'msg' => '请上传excel文件'
- ];
- }
- $file = time() . $this->store_id . '.' . $ext;
- $uploadfile = $path . $file;
- move_uploaded_file($tmpname, $uploadfile);
- $rows = \Spatie\SimpleExcel\SimpleExcelReader::create($uploadfile)
- ->getRows();
- $rowCount = $rows->count();
- if($rowCount > 200){
- return [
- 'code' => 1,
- 'msg' => '每次最大上传200条数据',
- ];
- }
- $rows = \Spatie\SimpleExcel\SimpleExcelReader::create($uploadfile)
- ->getRows();
- $arr = [];
- $arrErr = [];
- $rows->each(function (array $item) use (&$arr, &$arrErr) {
- try{
- if (isset($item['条码'])) {
- $pGoods = $this->hasGoodsBarcode($item['条码']);
- $goods = null;
- if($pGoods){
- $goods = Goods::findOne(['id' => $pGoods->goods_id]);
- }
- if(!$pGoods || !$goods){
- $res = $this->syncGoods(0, $item['条码']);
- if($res['code'] == 0){
- $arr[] = $res;
- }else{
- $arrErr[] = $res['msg'];
- }
- }
- //删除的商品修改状态
- if($goods && $goods->is_delete == 1){
- $goods->is_delete = 0;
- $goods->save();
- $arr[] = $goods;
- }
- }
- } catch (\Exception $e){
- \Yii::error([__METHOD__, $item, $e]);
- debug_log($e->getMessage());
- }
- });
-
- $count = count($arr);
- @unlink($uploadfile);
- $msg = '';
- if(count($arrErr)){
- $msg = ',错误:' . implode(',', $arrErr);
- }
- return [
- 'code' => $count ? 0 : 1,
- 'msg' => "共导入{$count}条数据" . $msg,
- ];
- }
- //从银豹同步商品图片
- public function importProductImgQueue($pageNo = 0, $okCount = 0, $hostInfo = null){
- $queue = queue_push(new \app\jobs\pospal\ImportProductImgJob([
- 'store_id' => $this->store_id,
- 'hostInfo' => $hostInfo ? $hostInfo : \Yii::$app->request->hostInfo,
- 'pageNo' => $pageNo,
- 'okCount' => $okCount,
- ]), 10);
- return [
- 'code' => 0,
- 'msg' => '操作成功,后台任务处理中,请在商品列表查看图片',
- ];
- }
- //从银豹同步商品图片
- public function importProductImgPage($param = [], $okCount = 0){
- if(!self::isopen($this->store_id)){
- return;
- }
- set_time_limit(0);
- $imgs = Api::queryProductImgPages($this->store_id, $param);
- if ($imgs['status'] == 'success') {
- $upload = new \app\models\common\Upload();
- $upload->store_id = $this->store_id;
- $upload->upload_config = \app\models\UploadConfig::getConf($this->store_id);
- $data = $imgs['data']['result'];
- foreach ($data as $img) {
- $syncImg = $this->syncProductImg($upload, $img);
- if($syncImg['code'] == 0){
- $okCount++;
- }else{
- \Yii::error([__METHOD__, $param, $okCount, $syncImg]);
- }
- }
- if(count($data) == $imgs['data']['pageSize']){
- empty($imgs['data']['postBackParameter']) || $param['postBackParameter'] = $imgs['data']['postBackParameter'];
- // return $this->importProductImg($param, $okCount);
- }
- return [
- 'code' => 0,
- 'msg' => '同步成功,数量:' . $okCount,
- ];
- }
- \Yii::error([__METHOD__, $param, $imgs]);
- return [
- 'code' => 1,
- 'msg' => '银豹商品图片数据获取失败,同步数量:' . $okCount,
- ];
- }
- //从银豹同步商品图片
- public function importProductImg($pageNo = 0, $okCount = 0){
- if(!self::isopen($this->store_id)){
- return;
- }
- set_time_limit(0);
- $upload = new \app\models\common\Upload();
- $upload->store_id = $this->store_id;
- $upload->upload_config = \app\models\UploadConfig::getConf($this->store_id);
- $pageSize = 100;
- $query = PospalGoods::find()->where(['store_id' => $this->store_id]);
- $list = $query->offset(($pageNo - 1) * $pageSize)->limit($pageSize)->orderBy('id DESC')->asArray()->all();
- foreach($list as $item){
- $imgs = Api::queryProductImagesByBarcode($this->store_id, $item['barcode']);
- if ($img = $imgs['data'][0]) {
- $syncImg = $this->syncProductImg($upload, $item, $img);
- if($syncImg['code'] == 0){
- $okCount++;
- }else{
- \Yii::error([__METHOD__, $param, $item['barcode'], $syncImg]);
- }
- }
- }
- if(count($list) == $pageSize){
- $this->importProductImgQueue($pageNo + 1, $okCount, $this->hostInfo);
- }
- \Yii::error([__METHOD__, $pageNo, $okCount]);
- return [
- 'code' => 0,
- 'msg' => '同步成功,数量:' . $okCount,
- ];
- }
- public function syncProductImg($upload, $item, $img) {
- $productUid = $item['productUid'];
- $imageUrl = $img['imageUrl'];
- if(empty($productUid) || empty($imageUrl)){
- return [
- 'code' => 1,
- 'msg' => '没有数据',
- ];
- }
- if(!$pgoods = $this->hasGoods($productUid)){
- \Yii::error([__METHOD__, $productUid, '商品没有同步']);die;
- return [
- 'code' => 1,
- 'msg' => '商品没有同步',
- ];
- }
- $goodsId = $pgoods['goods_id'];
- if(empty($goodsId)){
- return [
- 'code' => 1,
- 'msg' => '商品没有数据',
- ];
- }
- $uploadRes = $upload->downloadImg($imageUrl);
- if($uploadRes['code'] != 0){
- return $uploadRes;
- }
- $url = $uploadRes['url'];
- if (strpos($url, 'http') !== 0){
- $url = $this->hostInfo . $url;
- }
- Goods::updateAll(['cover_pic' => $url], ['id' => $goodsId]);
- $GoodsPic = \app\models\GoodsPic::findOne(['goods_id' => $goodsId]);
- if(empty($GoodsPic)){
- $goodsPic = new \app\models\GoodsPic();
- $goodsPic->goods_id = $goodsId;
- $goodsPic->pic_url = $url;
- $goodsPic->save();
- }
- return [
- 'code' => 0,
- 'msg' => '同步成功',
- ];
- }
- public function userList($params) {
- $query = PospalUser::find()->where(['store_id' => $this->store_id, 'is_delete' => 0]);
- if(!empty($params['name'])){
- $query->andWhere(['like', 'json', $params['name']]);
- }
- if(!empty($params['phone'])){
- $query->andWhere(['phone' => $params['phone']]);
- }
- if(!empty($params['number'])){
- $query->andWhere(['number' => $params['number']]);
- }
- if(!empty($params['customerUid'])){
- $query->andWhere(['customerUid' => $params['customerUid']]);
- }
- if(!empty($params['user_id'])){
- $query->andWhere(['user_id' => $params['user_id']]);
- }
- $data = pagination_make($query);
- foreach ($data['list'] as &$item) {
- $userid = $item['user_id'];
- $user = User::findOne($userid);
- $item['userInfo'] = $user;
- }
- return [
- 'code' => 0,
- 'msg' => 'ok',
- 'data' => $data,
- ];
- }
- public function productList($params) {
- $query = PospalGoods::find()->where(['store_id' => $this->store_id, 'is_delete' => 0]);
- if(!empty($params['name'])){
- $query->andWhere(['like', 'json', $params['name']]);
- }
- if(!empty($params['spu'])){
- $query->andWhere(['spu' => $params['spu']]);
- }
- if(!empty($params['barcode'])){
- $query->andWhere(['barcode' => $params['barcode']]);
- }
- if(!empty($params['productUid'])){
- $query->andWhere(['productUid' => $params['productUid']]);
- }
- if(!empty($params['goods_id'])){
- $query->andWhere(['goods_id' => $params['goods_id']]);
- }
- $data = pagination_make($query);
- foreach ($data['list'] as &$item) {
- $goodsid = $item['goods_id'];
- $goods = Goods::findOne($goodsid);
- $item['goodsInfo'] = $goods;
- }
- return [
- 'code' => 0,
- 'msg' => 'ok',
- 'data' => $data,
- ];
- }
- public function timeslimit() {
- $queryAccessTimes = Api::queryAccessTimes($this->store_id);
- $queryDailyAccessTimesLog = Api::queryDailyAccessTimesLog($this->store_id, [
- "beginDate" => date('Y-m-d', time() - 86400*3),
- "endDate" => date('Y-m-d'),
- ]);
- return [
- 'code' => 0,
- 'msg' => 'ok',
- 'queryAccessTimes' => $queryAccessTimes,
- 'queryDailyAccessTimesLog' => $queryDailyAccessTimesLog,
- ];
- }
- }
|