Order.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. <?php
  2. namespace Scm\Lib;
  3. use Dever;
  4. class Order
  5. {
  6. public function updateGoods($id, $name, $data)
  7. {
  8. $table = Dever::input('table');
  9. $goods = Dever::param('goods', $data);
  10. $cash = Dever::param('cash', $data);
  11. if ($table && $goods) {
  12. $temp = explode('-', $goods);
  13. $update = array();
  14. $update['where_id'] = $id;
  15. $update['goods_id'] = $temp[0];
  16. $update['sku_id'] = $temp[1];
  17. $batch = Dever::param('batch', $data);
  18. if (!$batch) {
  19. $update['batch'] = date('Ymd');
  20. }
  21. if (isset($temp[2]) && !$cash) {
  22. //$update['cash'] = $temp[2];
  23. }
  24. Dever::db($table)->update($update);
  25. Dever::config('base')->hook = false;
  26. }
  27. }
  28. public function updateOrderNum($id, $name, $data)
  29. {
  30. $servicer_store_id = Dever::param('servicer_store_id', $data);
  31. if ($servicer_store_id) {
  32. $info = Dever::db('scm_servicer/store')->find($servicer_store_id);
  33. if ($info && $info['type'] == 1 && (!$info['area'] || !$info['address'] || !$info['truename'] || !$info['tel'])) {
  34. Dever::alert('仓库[' . $info['name'] . ']收货地址未填写');
  35. }
  36. }
  37. $seller_shop_id = Dever::param('seller_shop_id', $data);
  38. if ($seller_shop_id) {
  39. $info = Dever::db('scm_seller/shop')->find($seller_shop_id);
  40. if ($info && $info['type'] == 1 && (!$info['area'] || !$info['address'] || !$info['truename'] || !$info['tel'])) {
  41. Dever::alert('门店[' . $info['name'] . ']收货地址未填写');
  42. }
  43. }
  44. $table = Dever::input('table');
  45. $prefix = Dever::input('prefix');
  46. if ($table && $prefix) {
  47. $update['order_num'] = $this->getOrderNum($table, $prefix);
  48. $update['where_id'] = $id;
  49. Dever::db($table)->update($update);
  50. Dever::config('base')->hook = false;
  51. }
  52. }
  53. # 生成订单号
  54. public function getOrderNum($table, $prefix = 'C')
  55. {
  56. $where['order_num'] = Dever::order($prefix);
  57. $state = Dever::db($table)->one($where);
  58. if (!$state) {
  59. return $where['order_num'];
  60. } else {
  61. return $this->getOrderNum($table);
  62. }
  63. }
  64. # 查看订单详情
  65. public function show($order_table)
  66. {
  67. $id = Dever::input('order_id');
  68. $order_db = Dever::db($order_table);
  69. $order = $order_db->one($id);
  70. $order['config'] = $order_db->config['set'];
  71. $content = array();
  72. if (isset($order['type'])) {
  73. $type = Dever::db($order_table . '_type')->one($order['type']);
  74. $content[0][] = array('订单类型', $type['name']);
  75. }
  76. $content[0][] = array('订单状态', Dever::status($order['config']['status'], $order['status']));
  77. $content[0][] = array('下单时间', date('Y-m-d H:i', $order['cdate']));
  78. $order['info'] && $content[0][] = array('订单备注', $order['info']);
  79. $content[1] = $content[2] = array();
  80. $role = $this->show_role(array
  81. (
  82. 'seller' => '经销商',
  83. 'seller_shop' => '门店',
  84. 'servicer' => '配送商',
  85. 'servicer_store' => '仓库',
  86. 'supplier' => '供应商',
  87. ), $order, $content[1]);
  88. $this->show_audit($order, $content[2]);
  89. $result = array();
  90. $result[$order['order_num']] = array
  91. (
  92. 'type' => 'info',
  93. 'content' => $content
  94. );
  95. $this->show_address($order, $role, $result);
  96. $audit = Dever::input('audit');
  97. if ($audit == 1) {
  98. $this->show_goods_audit($order, $order_table, $result);
  99. } else {
  100. $this->show_goods($order, $order_table, $result);
  101. }
  102. $head = array
  103. (
  104. 'name' => '基本信息',
  105. 'btn' => $this->show_button($order, $order_table),
  106. );
  107. $html = Dever::show($head, $result);
  108. return $html;
  109. }
  110. # 显示订单角色
  111. private function show_role($role, $order, &$data)
  112. {
  113. $result = array();
  114. foreach ($role as $k => $v) {
  115. $col = $k . '_id';
  116. if (isset($order[$col]) && $order[$col] > 0) {
  117. $project = $k;
  118. $name = 'info';
  119. if (strstr($k, '_')) {
  120. $temp = explode('_', $k);
  121. $project = $temp[0];
  122. $name = $temp[1];
  123. }
  124. $table = 'scm_' . $project . '/' . $name;
  125. $result[$k] = Dever::db($table)->one($order[$col]);
  126. if ($result[$k]) {
  127. $data[] = array($v, $result[$k]['name']);
  128. }
  129. }
  130. }
  131. return $result;
  132. }
  133. # 显示审核信息
  134. private function show_audit($order, &$data)
  135. {
  136. if (isset($order['audit_admin']) && $order['audit_admin']) {
  137. $admin = Dever::db('manage/admin')->find($order['audit_admin']);
  138. $data = array
  139. (
  140. array('审核人', $admin['username']),
  141. array('审核状态', Dever::status($order['config']['audit'], $order['audit'])),
  142. array('审核备注', $order['audit_desc']),
  143. );
  144. }
  145. }
  146. # 显示订单地址
  147. private function show_address($order, $role, &$result)
  148. {
  149. if (!$order['address']) {
  150. if (isset($role['servicer_store'])) {
  151. $address = $role['servicer_store'];
  152. }
  153. if (isset($role['seller_shop'])) {
  154. $address = $role['seller_shop'];
  155. }
  156. } else {
  157. $address = Dever::json_decode($order['address']);
  158. }
  159. if ($address) {
  160. $address['area'] = Dever::load('area/api')->string($address['area']);
  161. $result['收货信息'] = array
  162. (
  163. 'type' => 'info',
  164. 'content' => array
  165. (
  166. array
  167. (
  168. array('联系人', $address['truename']),
  169. array('联系电话', $address['tel']),
  170. array('收货地址', $address['area'] . ',' . $address['address']),
  171. ),
  172. ),
  173. );
  174. }
  175. }
  176. # 显示订单商品清单
  177. private function show_goods($order, $order_table, &$result)
  178. {
  179. $data = Dever::db($order_table . '_goods')->select(array('order_id' => $order['id']));
  180. if ($data) {
  181. $table['head'] = array('商品编码', '商品名称', '批次', '单价', '数量', '总价', '状态');
  182. $table['body'] = array();
  183. $total_price = $total_num = 0;
  184. $status = Dever::db($order_table . '_goods')->config['status'];
  185. foreach ($data as $k => $v) {
  186. $goods_info = Dever::load('scm_product/lib/info')->getBaseInfo($v['goods_id'], $v['sku_id'], $v['unit_id']);
  187. $status_name = Dever::status($status, $v['status']);
  188. $num = $v['num'];
  189. if ($v['status'] == 2 && $v['unit_id'] != $goods_info['base_unit_id']) {
  190. if (!isset($order['supplier_id'])) {
  191. $order['supplier_id'] = false;
  192. }
  193. $unit = Dever::load('scm/lib/unit')->convertBase($v['goods_id'], $v['sku_id'], $v['unit_id'], $v['num'], $v['cash'], 0, $order['supplier_id']);
  194. if ($unit) {
  195. $base_unit = Dever::db('scm/unit')->find($unit['unit_id']);
  196. $goods_info['unit'] .= ' => '.$unit['num'].''.$base_unit['name'].'';
  197. $num = $unit['num'];
  198. }
  199. }
  200. $cash = Dever::number($v['cash'] * $v['num']);
  201. $detail = array
  202. (
  203. $goods_info['code'],
  204. $goods_info['aname'],
  205. );
  206. if (isset($v['batch'])) {
  207. $detail[] = $v['batch'] . (isset($v['sdate']) && $v['sdate'] ? '[' . date('Y-m-d', $v['sdate']) . '生产]' : '');
  208. } else {
  209. unset($table['head'][3]);
  210. }
  211. $detail[] = $v['cash'];
  212. $detail[] = $v['num'] . $goods_info['unit'];
  213. $detail[] = $cash;
  214. $detail[] = $status_name;
  215. if ($goods_info['goods']) {
  216. $detail['goods'] = $goods_info['goods'];
  217. }
  218. $table['body'][] = $detail;
  219. $total_price += $cash;
  220. $total_num += $num;
  221. }
  222. $result['商品清单'] = array
  223. (
  224. 'type' => 'table',
  225. 'head' => array('name' => '', 'btn' => ''),
  226. 'content' => $table,
  227. 'total' => '合计金额:' . Dever::number($total_price) . ',合计数量:' . $total_num
  228. );
  229. }
  230. }
  231. # 显示按钮
  232. private function show_button($order, $order_table)
  233. {
  234. $button = array();
  235. if ($order['status'] == 1) {
  236. list($project, $table) = explode('/', $order_table);
  237. $url = Dever::url('project/database/update?project='.$project.'&table='.$table.'&where_id='.$order['id'].'&col=audit,audit_desc', 'manage');
  238. $button[] = array
  239. (
  240. 'type' => 'edit',
  241. 'link' => $url,
  242. 'name' => '审核',
  243. );
  244. }
  245. return $button;
  246. }
  247. private function show_goods_audit($order, $order_table, &$result)
  248. {
  249. $order['type'] = 1;
  250. $data = Dever::db($order_table . '_goods')->select(array('order_id' => $order['id']));
  251. $shop = Dever::db('shop/info')->find($order['type_id']);
  252. list($assign, $source) = Dever::load('scm/lib/assign')->get($goods, $info, $shop, true);
  253. if ($info) {
  254. $head = array('商品编码', '商品名称', '批次', '单价', '数量', '总价', '供货商');
  255. $body = array();
  256. $i = 0;
  257. if ($data) {
  258. foreach ($assign as $k => $v) {
  259. foreach ($v as $v1) {
  260. $goods_info = Dever::load('goods/lib/info')->getInfoBySku($v1['goods_id'], $v1['sku_id']);
  261. if (isset($goods_info['sku'])) {
  262. $sku = '[' . $goods_info['sku']['string'] . ']';
  263. } else {
  264. $sku = '';
  265. }
  266. $d = array
  267. (
  268. $i+1,
  269. $goods_info['code'],
  270. $goods_info['name'] . $sku,
  271. $this->getSelect($source, $v1['source_id'], $v1['order_goods_id']),
  272. $v1['num'],
  273. $goods_info['unit'],
  274. $v1['p_price'] * $v1['num'],
  275. );
  276. $body[] = $d;
  277. $i++;
  278. }
  279. }
  280. }
  281. if ($goods) {
  282. foreach ($goods as $k => $v) {
  283. $goods_info = Dever::load('goods/lib/info')->getInfoBySku($v['goods_id'], $v['sku_id']);
  284. if (isset($goods_info['sku'])) {
  285. $sku = '[' . $goods_info['sku']['string'] . ']';
  286. } else {
  287. $sku = '';
  288. }
  289. $d = array
  290. (
  291. $i+1,
  292. $goods_info['code'],
  293. $goods_info['name'] . $sku,
  294. $this->getSelect($source, false, $v['id']),
  295. $v['num'],
  296. $goods_info['unit'],
  297. $v['p_price'] * $v['num'],
  298. );
  299. $body[] = $d;
  300. $i++;
  301. }
  302. }
  303. $btn = array();
  304. $btn[] = array(
  305. 'type' => 'click',
  306. 'content' => 'setAudit()',
  307. 'name' => '全部调整<script>function setAudit(){layer.confirm(\'确定进行此项操作吗?\', function(){var audit = $(\'.audit_set\').val();$(\'.audit\').each(function(){$(this).val(audit);layui.form.render();layer.closeAll()})})}</script>'
  308. );
  309. $result['商品拆单'] = array
  310. (
  311. 'type' => 'table',
  312. 'head' => array('name' => '供货商:' . $this->getSelect($source, false, false), 'btn' => $btn),
  313. 'content' => array
  314. (
  315. 'head' => $head,
  316. 'body' => $body,
  317. )
  318. );
  319. $url = Dever::url('lib/buy.audit_set_commit?json=1&order_id=' . $info['id'], 'mshop');
  320. $result['审核结果'] = array
  321. (
  322. 'type' => 'html',
  323. 'content' => '<script>function saveAudit(){var goods = [];var audit = 1; var audit_text = $(".update_audit_text").val();$(".update_audit").each(function(){if ($(this).get(0).checked){audit = $(this).val()}});$(\'.audit\').each(function(){var v = $(this).val();var id = $(this).attr("id");goods.push(v + "_" + id);});layer.confirm(\'确定进行此项操作吗?\', function(){layui.form.render();var send = {};send.goods = goods.join(",");send.audit = audit;send.audit_text = audit_text;console.info(send);$.post("'.$url.'", send, function(t){t = JSON.parse(t);showYes(t)})})}</script><style>.layui-form-radio{padding-right: 0px;margin: 0px 0px 0 0;margin-left:40px}</style><div class="layui-form-item show_input"><div classs="layui-col-lg6"><div><label style="font-size:14px;font-weight:bold;" class="">审核状态</label><div style="display:inline" class="am-btn-group"><input update_type="checked" class="checkbox-checkall-0_update_audit update_audit update_value validate[required]" type="radio" name="update_audit[]" value="2" checked="" show_id="audit" autocomplete="off" id="form-validation-field-1"> 审核通过 &nbsp;&nbsp;<input update_type="checked" class="autoload checkbox-checkall-0_update_audit update_audit update_value validate[required]" type="radio" name="update_audit[]" value="3" autocomplete="off" id="form-validation-field-0"> 审核未通过 &nbsp;&nbsp;</div></div></div></div><div class="layui-form-item" style="display: block;"><div classs="layui-col-lg6"><div><label style="font-size:14px;font-weight:bold;" class="">审核备注</label></div><div><textarea style="height:100px;" update_type="value" class="update_value update_audit_text form-control layui-input validate[required]" name="update_desc"></textarea></div></div></div> <div style="text-align:left" class="layui-layer-btn layui-layer-btn-"><a class="layui-btn layui-btn-primary" onclick="saveAudit()">保存</a><a class="layui-layer-btn1" style="display:none">取消</a></div>',
  324. );
  325. }
  326. }
  327. }